ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2026-01-20 05:20:45
Exec Total Coverage
Lines: 3090 8763 35.3%
Functions: 86 314 27.4%
Branches: 2691 7939 33.9%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/pal_tables.h"
10 #include "base/version.h"
11 #include "base/zapp.h"
12 #include "base/zdefs.h"
13 #include "dialog/info.h"
14 #include "gui/jwin.h"
15 #include "metadata/metadata.h"
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/packfile.h"
20 #include "base/cpool.h"
21 #include "base/autocombo.h"
22 #include "base/gui.h"
23 #include "base/msgstr.h"
24 #include "zc/zelda.h"
25 #include "zq/zq_class.h"
26 #include "zq/render.h"
27 #include "zq/render_map_view.h"
28 #include "zq/zq_misc.h"
29 #include "zq/zquest.h"
30 #include "base/qst.h"
31 #include "base/colors.h"
32 #include "tiles.h"
33 #include "base/zsys.h"
34 #include "sprite.h"
35 #include "items.h"
36 #include "zc/zc_sys.h"
37 #include "base/md5.h"
38 #include "hero_tiles.h"
39 #include "subscr.h"
40 #include "zq/zq_strings.h"
41 #include "zq/zq_subscr.h"
42 #include "zc/ffscript.h"
43 #include "base/util.h"
44 #include "zq/zq_files.h"
45 #include "slopes.h"
46 #include "drawing.h"
47 #include "zinfo.h"
48 #include "zq/render_minimap.h"
49 #include "base/mapscr.h"
50 #include "iter.h"
51 #include <fmt/format.h>
52 #include <filesystem>
53 #include "advanced_music.h"
54
55 #ifdef __EMSCRIPTEN__
56 #include "base/emscripten_utils.h"
57 #endif
58
59 namespace fs = std::filesystem;
60
61 using namespace util;
62
63 extern uint8_t ViewLayer3BG, ViewLayer2BG;
64 extern int32_t LayerDitherBG, LayerDitherSz;
65 extern bool NoHighlightLayer0;
66
67 using std::string;
68 using std::pair;
69
70 #define COLOR_SOLID vc(4)
71 #define COLOR_SLOPE vc(13)
72 #define COLOR_LADDER vc(6)
73 //#define COLOR_EFFECT vc(10)
74
75 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
76 extern char msgbuf[MSG_NEW_SIZE*8];
77
78 extern string zScript;
79
80 12 zmap Map;
81 int32_t prv_mode=0;
82
83 bool save_warn=true;
84
85 int32_t COMBOPOS(int32_t x, int32_t y)
86 {
87 return (((y) & 0xF0) + ((x) >> 4));
88 }
89 int32_t COMBOPOS_B(int32_t x, int32_t y)
90 {
91 if(unsigned(x) >= 256 || unsigned(y) >= 176)
92 return -1;
93 return COMBOPOS(x,y);
94 }
95 int32_t COMBOX(int32_t pos)
96 {
97 return ((pos) % 16 * 16);
98 }
99 int32_t COMBOY(int32_t pos)
100 {
101 return ((pos) & 0xF0);
102 }
103
104 void reset_dmap(int32_t index)
105 {
106 bound(index,0,MAXDMAPS-1);
107 DMaps[index].clear();
108 DMaps[index].title = "";
109 sprintf(DMaps[index].intro, " ");
110 }
111
112 void reset_dmaps()
113 {
114 for(int32_t i=0; i<MAXDMAPS; i++)
115 reset_dmap(i);
116 }
117
118 void truncate_dmap_title(std::string& title)
119 {
120 title.resize(21, ' ');
121 }
122
123 mapscr* zmap::get_prvscr()
124 {
125 return &prvscr;
126 }
127
128
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23 times.
✗ Branch 11 not taken.
138 zmap::zmap()
129 {
130 23 can_paste=false;
131 23 prv_cmbcycle=0;
132 23 prv_advance=0;
133 23 prv_freeze=0;
134 23 copyffc=-1;
135
136 23 memset(scrpos, 0, sizeof(scrpos));
137 23 memset(scrview, 0, sizeof(scrview));
138 23 screens=NULL;
139 23 prv_time=0;
140 23 prv_scr=0;
141 23 prv_map=0;
142 23 copyscr=0;
143 23 cursor={};
144 copymap=0;
145 layer_target_map = 0;
146 layer_target_scr = 0;
147 layer_target_multiple = 0;
148 }
149
150 11 void zmap::clear()
151 {
152
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
153 11 }
154 void zmap::force_refr_pointer()
155 {
156 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
157 screens = nullptr;
158 else screens = &TheMaps[cursor.map*MAPSCRS];
159 }
160 bool zmap::CanUndo()
161 {
162 return input_undo_stack.size() > 0;
163 }
164 bool zmap::CanRedo()
165 {
166 return input_redo_stack.size() > 0;
167 }
168 bool zmap::CanPaste()
169 {
170 return can_paste;
171 }
172 int32_t zmap::CopyScr()
173 {
174 return (copymap<<8)+copyscr;
175 }
176 int32_t zmap::getCopyFFC()
177 {
178 return copyffc;
179 }
180 set_ffc_command::data_t zmap::getCopyFFCData()
181 {
182 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
183 }
184 67 int32_t zmap::getMapCount()
185 {
186 67 return map_count;
187 }
188 int32_t zmap::getLayerTargetMap()
189 {
190 return layer_target_map;
191 }
192 int32_t zmap::getLayerTargetScr()
193 {
194 return layer_target_scr;
195 }
196 int32_t zmap::getLayerTargetMultiple()
197 {
198 return layer_target_multiple;
199 }
200 bool zmap::isDungeon(int32_t scr)
201 {
202 for(int32_t i=0; i<4; i++)
203 {
204 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
205 {
206 return false;
207 }
208 }
209
210 return true;
211 }
212
213 bool zmap::clearall(bool validate)
214 {
215 Color=0;
216 char tbuf[10];
217
218 if((header.templatepath[0]!=0)&&validate)
219 {
220 if(!valid_zqt(header.templatepath))
221 {
222 displayinfo("Error","Invalid Quest Template");
223 return false;
224 }
225 }
226
227 for(int32_t i=0; i<map_count; i++)
228 {
229 setCurrMap(i);
230 sprintf(tbuf, "%d", i);
231 clearmap(true);
232 }
233
234 setCurrMap(0);
235 return true;
236 }
237
238 bool zmap::reset_templates(bool validate)
239 {
240 //why are we doing this?
241 if(colordata==NULL)
242 {
243 return false;
244 }
245
246 //int32_t ret;
247 word version, build, dummy, sversion=0;
248 byte dummyc;
249 word dummyw;
250 //int32_t section_size;
251 word temp_map_count;
252 mapscr temp_mapscr;
253 PACKFILE *f=NULL;
254
255 // setPackfilePassword(datapwd);
256 f=open_quest_template(&header, "modules/classic/default.qst", validate);
257 get_version_and_build(f, &version, &build);
258
259 if(!find_section(f, ID_MAPS))
260 {
261 // setPackfilePassword(NULL);
262 return false;
263 }
264
265 //section version info
266 if(!p_igetw(&sversion,f))
267 {
268 return false;
269 }
270
271 if(!p_igetw(&dummy,f))
272 {
273 return false;
274 }
275
276 //section size
277 dword dummy_size;
278 if(!p_igetl(&dummy_size,f))
279 {
280 return false;
281 }
282
283 //finally... section data
284 if(!p_igetw(&temp_map_count,f))
285 {
286 return false;
287 }
288
289 if(version>12)
290 {
291 if(!p_getc(&dummyc,f))
292 return qe_invalid;
293
294 if(!p_getc(&dummyc,f))
295 return qe_invalid;
296
297 if(!p_igetw(&dummyw,f))
298 return qe_invalid;
299
300 if(!p_igetw(&dummyw,f))
301 return qe_invalid;
302
303 if(!p_igetw(&dummyw,f))
304 return qe_invalid;
305
306 if(!p_igetw(&dummyw,f))
307 return qe_invalid;
308
309 if(!p_igetw(&dummyw,f))
310 return qe_invalid;
311
312 if(!p_igetw(&dummyw,f))
313 return qe_invalid;
314
315 if(!p_igetw(&dummyw,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_getc(&dummyc,f))
328 return qe_invalid;
329
330 if(!p_getc(&dummyc,f))
331 return qe_invalid;
332 }
333
334 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
335 {
336 readmapscreen(f, &header, &temp_mapscr, sversion);
337 }
338
339 readmapscreen(f, &header, &TheMaps[128], sversion);
340 readmapscreen(f, &header, &TheMaps[129], sversion);
341
342 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
343 {
344 readmapscreen(f, &header, &temp_mapscr, sversion);
345 }
346
347 if(version>12)
348 {
349 if(!p_getc(&dummyc,f))
350 return qe_invalid;
351
352 if(!p_getc(&dummyc,f))
353 return qe_invalid;
354
355 if(!p_igetw(&dummyw,f))
356 return qe_invalid;
357
358 if(!p_igetw(&dummyw,f))
359 return qe_invalid;
360
361 if(!p_igetw(&dummyw,f))
362 return qe_invalid;
363
364 if(!p_igetw(&dummyw,f))
365 return qe_invalid;
366
367 if(!p_igetw(&dummyw,f))
368 return qe_invalid;
369
370 if(!p_igetw(&dummyw,f))
371 return qe_invalid;
372
373 if(!p_igetw(&dummyw,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_getc(&dummyc,f))
386 return qe_invalid;
387
388 if(!p_getc(&dummyc,f))
389 return qe_invalid;
390 }
391
392 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
393 {
394 readmapscreen(f, &header, &temp_mapscr, sversion);
395 }
396
397 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
398 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
399
400 pack_fclose(f);
401 clear_quest_tmpfile();
402
403 return true;
404 }
405
406 bool zmap::clearmap(bool newquest)
407 {
408 if(cursor.map<map_count)
409 {
410 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
411 {
412 clearscr(i);
413 }
414
415 setCurrScr(0);
416
417 if(newquest)
418 {
419 if(!reset_templates(false))
420 {
421 displayinfo("Error","Error resetting template screens.");
422 }
423 }
424 }
425
426 return true;
427 }
428
429 MapCursor zmap::getCursor() const
430 {
431 return cursor;
432 }
433
434 11 void zmap::setCursor(MapCursor new_cursor)
435 {
436
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if (cursor == new_cursor && screens)
437 return;
438
439
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (screens)
440 pushCursorToHistory(std::move(cursor));
441 11 cursor = std::move(new_cursor);
442
443
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
444 11 screens = &TheMaps[cursor.map*MAPSCRS];
445
446 11 refresh_color();
447 11 setlayertarget();
448 11 reset_combo_animations2();
449 11 mmap_mark_dirty();
450 11 regions_mark_dirty();
451 11 }
452
453 void zmap::pushCursorToHistory(MapCursor cursor)
454 {
455 if (cursor_history_enabled)
456 {
457 cursor_undo_stack.push_back(std::move(cursor));
458 cursor_redo_stack = {};
459 CapCursorHistory();
460 }
461 }
462
463 bool zmap::isValidPosition(ComboPosition pos) const
464 {
465 return pos.is_valid(cursor);
466 }
467
468 int zmap::getScreenForPosition(ComboPosition pos) const
469 {
470 return cursor.viewscr + pos.screen_offset();
471 }
472
473 mapscr* zmap::CurrScr()
474 {
475 return screens+cursor.screen;
476 }
477 mapscr* zmap::Scr(int32_t scr)
478 {
479 return screens+scr;
480 }
481 mapscr* zmap::Scr(ComboPosition pos)
482 {
483 if (!pos.is_valid(cursor))
484 return nullptr;
485
486 int screen_offset = pos.screen_offset();
487 int screen = cursor.viewscr + screen_offset;
488 return AbsoluteScr(cursor.map, screen);
489 }
490 mapscr* zmap::Scr(ComboPosition pos, int layer)
491 {
492 int map = cursor.map;
493 int screen = cursor.viewscr + pos.screen_offset();
494 if (layer)
495 {
496 mapscr* scr = Map.AbsoluteScr(map, screen);
497 map = scr->layermap[CurrentLayer-1]-1;
498 screen = scr->layerscreen[CurrentLayer-1];
499 }
500
501 return AbsoluteScr(map, screen);
502 }
503 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
504 {
505 mapscr* scr = Scr(pos, layer);
506 if (scr && !(scr->valid&mVALID))
507 {
508 scr->valid |= mVALID;
509 setcolor(Color, scr);
510 }
511 return scr;
512 }
513 mapscr* zmap::AbsoluteScr(int32_t scr)
514 {
515 if(unsigned(scr) >= MAPSCRS*getMapCount())
516 return nullptr;
517 return &TheMaps[scr];
518 }
519 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
520 {
521 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
522 return nullptr;
523 return AbsoluteScr((map*MAPSCRS)+scr);
524 }
525 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
526 {
527 mapscr* scr = AbsoluteScr(map, screen);
528 if (scr && !(scr->valid&mVALID))
529 {
530 scr->valid |= mVALID;
531 setcolor(Color, scr);
532 }
533 return scr;
534 }
535 void zmap::set_prvscr(int32_t map, int32_t scr)
536 {
537 prvscr = *get_canonical_scr(map, scr);
538
539 for(int32_t i=0; i<6; i++)
540 {
541 if(prvscr.layermap[i]>0)
542 {
543 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
544 }
545 else
546 prvlayers[i].valid = 0;
547 }
548
549 prv_map=map;
550 prv_scr=scr;
551 }
552 92 int32_t zmap::getCurrMap()
553 {
554 92 return cursor.map;
555 }
556 11 void zmap::regions_mark_dirty()
557 {
558 11 regions_dirty = true;
559 11 }
560 void zmap::regions_refresh()
561 {
562 if (!regions_dirty)
563 return;
564
565 regions_dirty = false;
566 region_descriptions.clear();
567
568 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
569 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
570 region_descriptions.clear();
571 }
572 const std::vector<region_description>& zmap::get_region_descriptions()
573 {
574 regions_refresh();
575 return region_descriptions;
576 }
577 bool zmap::is_region(int screen)
578 {
579 if (screen < 0 || screen >= 128)
580 return false;
581
582 regions_refresh();
583 return current_map_region_ids[screen];
584 }
585 bool zmap::isDark(int scr)
586 {
587 return (screens[scr].flags&fDARK)!=0;
588 }
589 bool zmap::isValid(int32_t scr)
590 {
591 return (screens[scr].valid&mVALID)!=0;
592 }
593 bool zmap::isValid(int32_t map, int32_t scr)
594 {
595 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
596 }
597
598 void zmap::setCurrMap(int32_t index)
599 {
600 scrpos[cursor.map] = cursor.screen;
601 scrview[cursor.map] = cursor.viewscr;
602
603 auto new_cursor = cursor;
604 new_cursor.map = bound(index,0,map_count);
605
606 new_cursor.viewscr = scrview[new_cursor.map];
607 new_cursor.setScreen(scrpos[new_cursor.map]);
608 setCursor(std::move(new_cursor));
609 }
610
611 20 int32_t zmap::getCurrScr()
612 {
613 20 return cursor.screen;
614 }
615 void zmap::setCurrScr(int32_t scr)
616 {
617 if (scr == cursor.screen)
618 return;
619
620 auto new_cursor = cursor;
621 new_cursor.setScreen(scr);
622 setCursor(std::move(new_cursor));
623 }
624
625 int32_t zmap::getViewScr()
626 {
627 return cursor.viewscr;
628 }
629
630 void zmap::setViewSize(int32_t size)
631 {
632 auto new_cursor = cursor;
633 new_cursor.setSize(size);
634 setCursor(std::move(new_cursor));
635 }
636
637 1 int32_t zmap::getViewSize()
638 {
639 1 return cursor.size;
640 }
641
642 11 void zmap::setlayertarget()
643 {
644 11 layer_target_map = 0;
645 11 layer_target_multiple = 0;
646
647
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
648 {
649
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
650 {
651 7616 int32_t i=(m*MAPSCRS+s);
652 7616 mapscr *ts=&TheMaps[i];
653
654 // Search through each layer
655
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
656 {
657
3/4
✓ Branch 0 taken 15868 times.
✓ Branch 1 taken 29828 times.
✓ Branch 2 taken 15868 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
658 {
659 if(layer_target_map > 0)
660 {
661 layer_target_multiple += 1;
662 continue;
663 }
664
665 layer_target_map = m+1;
666 layer_target_scr = s;
667 }
668 45696 }
669 7616 }
670 56 }
671 11 }
672
673 11 void zmap::refresh_color()
674 {
675 11 auto color = getcolor();
676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (Color != color)
677 {
678 11 loadlvlpal(color);
679 11 rebuild_trans_table();
680 11 }
681 11 }
682
683 void zmap::setcolor(int color, mapscr* scr)
684 {
685 if (!scr)
686 scr = CurrScr();
687 scr->valid |= mVALID;
688 scr->color = color;
689
690 refresh_color();
691
692 mmap_mark_dirty();
693 }
694
695 11 int32_t zmap::getcolor()
696 {
697 11 return getcolor(cursor.screen);
698 }
699
700 11 int32_t zmap::getcolor(int screen)
701 {
702
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 mapscr& scr = prv_mode ? prvscr : screens[screen];
703
704
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (scr.valid & mVALID)
705 11 return scr.color;
706
707 return map_infos[cursor.map].autopalette;
708 11 }
709
710 void zmap::resetflags()
711 {
712 byte *di=&(screens[cursor.screen].valid);
713
714 for(int32_t i=1; i<48; i++)
715 {
716 *(di+i)=0;
717 }
718 }
719
720 word zmap::tcmbdat(int32_t pos)
721 {
722 return screens[TEMPLATE].data[pos];
723 }
724
725 word zmap::tcmbcset(int32_t pos)
726 {
727 return screens[TEMPLATE].cset[pos];
728 }
729
730 int32_t zmap::tcmbflag(int32_t pos)
731 {
732 return screens[TEMPLATE].sflag[pos];
733 }
734
735 word zmap::tcmbdat2(int32_t pos)
736 {
737 return screens[TEMPLATE2].data[pos];
738 }
739
740 word zmap::tcmbcset2(int32_t pos)
741 {
742 return screens[TEMPLATE2].cset[pos];
743 }
744
745 int32_t zmap::tcmbflag2(int32_t pos)
746 {
747 return screens[TEMPLATE2].sflag[pos];
748 }
749
750 void zmap::TemplateAll()
751 {
752 StartListCommand();
753 for(int32_t i=0; i<128; i++)
754 {
755 if((screens[i].valid&mVALID) && isDungeon(i))
756 DoTemplateCommand(-1, -1, i);
757 }
758 FinishListCommand();
759 }
760
761 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
762 {
763 if(scr==TEMPLATE)
764 return;
765
766 if(!(screens[scr].valid&mVALID))
767 screens[scr].color=Color;
768
769 screens[scr].valid|=mVALID;
770
771 for(int32_t i=0; i<32; i++)
772 {
773 screens[scr].data[i]=screens[TEMPLATE].data[i];
774 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
775 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
776 }
777
778 for(int32_t i=144; i<176; i++)
779 {
780 screens[scr].data[i]=screens[TEMPLATE].data[i];
781 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
782 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
783 }
784
785 for(int32_t y=2; y<=9; y++)
786 {
787 int32_t j=y<<4;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 screens[scr].data[j]=screens[TEMPLATE].data[j];
793 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
794 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
795 ++j;
796 j+=12;
797 screens[scr].data[j]=screens[TEMPLATE].data[j];
798 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
799 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
800 ++j;
801 screens[scr].data[j]=screens[TEMPLATE].data[j];
802 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
803
804 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
805 ++j;
806 }
807
808 if(floorcombo!=-1)
809 {
810 for(int32_t y=2; y<9; y++)
811 for(int32_t x=2; x<14; x++)
812 {
813 int32_t i=(y<<4)+x;
814 screens[scr].data[i] = floorcombo;
815 screens[scr].cset[i] = floorcset;
816 }
817 }
818
819 for(int32_t i=0; i<4; i++)
820 putdoor(scr,i,screens[scr].door[i]);
821 }
822
823
824 void zmap::clearscr(int32_t scr)
825 {
826 screens[scr].zero_memory();
827 screens[scr].valid=mVERSION;
828 auto const& mapinf = map_infos[cursor.map];
829 for(int q = 0; q < 6; ++q)
830 {
831 auto layer = mapinf.autolayers[q];
832 screens[scr].layermap[q] = layer;
833 screens[scr].layerscreen[q] = layer ? scr : 0;
834 }
835 screens[scr].color = mapinf.autopalette;
836 if (scr == cursor.screen)
837 refresh_color();
838 mmap_mark_dirty();
839 }
840
841 const char *loaderror[] =
842 {
843
844 "OK","File not found","Incomplete data",
845 "Invalid version","Invalid file"
846
847 };
848
849 int32_t zmap::load(const char *path)
850 {
851 PACKFILE *f=pack_fopen_password(path,F_READ, "");
852
853 if(!f)
854 return 1;
855
856
857 int16_t version;
858 byte build;
859
860 //get the version
861 if(!p_igetw(&version,f))
862 {
863 goto file_error;
864 }
865
866 //get the build
867 if(!p_getc(&build,f))
868 {
869 goto file_error;
870 }
871
872 for(int32_t i=0; i<MAPSCRS; i++)
873 {
874 mapscr tmpimportscr;
875 tmpimportscr.zero_memory();
876 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
877 {
878 al_trace("failed zmap::load\n");
879 goto file_error;
880 }
881
882 switch(ImportMapBias)
883 {
884 case 0:
885 *(screens+i) = tmpimportscr;
886 break;
887
888 case 1:
889 if(!(screens[i].valid&mVALID))
890 {
891 *(screens+i) = tmpimportscr;
892 }
893 break;
894
895 case 2:
896 if(tmpimportscr.valid&mVALID)
897 {
898 *(screens+i) = tmpimportscr;
899 }
900 break;
901 }
902 }
903
904
905 pack_fclose(f);
906
907 setCurrScr(0);
908 mmap_mark_dirty();
909 regions_mark_dirty();
910 return 0;
911
912 file_error:
913 pack_fclose(f);
914 clearmap(false);
915 return 2;
916 }
917
918 int32_t zmap::save(const char *path)
919 {
920 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
921
922 if(!f)
923 return 1;
924
925 if(!p_iputw(V_MAPS,f))
926 {
927 pack_fclose(f);
928 return 3;
929 }
930
931 // This was the "build number", but that's totally useless here. Keep this junk byte
932 // so as not to totally break exports between ZC versions.
933 if(!p_putc(0,f))
934 {
935 pack_fclose(f);
936 return 3;
937 }
938
939 for(int32_t i=0; i<MAPSCRS; i++)
940 {
941 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
942 {
943 pack_fclose(f);
944 return 2;
945 }
946 }
947
948 pack_fclose(f);
949 return 0;
950 }
951
952
953 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
954 {
955 // Hookshots can be blocked by solid combos on all 3 ground layers.
956 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
957
958 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
959 return true;
960 if (c->walk&(1<<i))
961 return false;
962
963 for(int32_t k=0; k<2; k++)
964 {
965 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
966
967 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
968 {
969 return false;
970 }
971 }
972
973 return true;
974 }
975
976 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
977 {
978 // Hookshots can be blocked by solid combos on all 3 ground layers.
979 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
980
981 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
982 return true;
983 if (c->walk&(1<<i))
984 return false;
985
986 for(int32_t k=0; k<2; k++)
987 {
988 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
989
990 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
991 {
992 return false;
993 }
994 }
995
996 return true;
997 }
998
999 bool zmap::isstepable(int32_t combo)
1000 {
1001 // This is kind of odd but it's true to the engine (see maps.cpp)
1002 return (combo_class_buf[combobuf[combo].type].ladder_pass);
1003 }
1004
1005 // Returns the letter of the warp combo.
1006 int32_t zmap::warpindex(int32_t combo)
1007 {
1008 switch(combobuf[combo].type)
1009 {
1010 case cCAVE:
1011 case cPIT:
1012 case cSTAIR:
1013 case cCAVE2:
1014 case cSWIMWARP:
1015 case cDIVEWARP:
1016 case cSWARPA:
1017 return 0;
1018
1019 case cCAVEB:
1020 case cPITB:
1021 case cSTAIRB:
1022 case cCAVE2B:
1023 case cSWIMWARPB:
1024 case cDIVEWARPB:
1025 case cSWARPB:
1026 return 1;
1027
1028 case cCAVEC:
1029 case cPITC:
1030 case cSTAIRC:
1031 case cCAVE2C:
1032 case cSWIMWARPC:
1033 case cDIVEWARPC:
1034 case cSWARPC:
1035 return 2;
1036
1037 case cCAVED:
1038 case cPITD:
1039 case cSTAIRD:
1040 case cCAVE2D:
1041 case cSWIMWARPD:
1042 case cDIVEWARPD:
1043 case cSWARPD:
1044 return 3;
1045
1046 case cPITR:
1047 case cSTAIRR:
1048 case cSWARPR:
1049 return 4;
1050 }
1051
1052 return -1;
1053
1054 }
1055
1056 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1057 {
1058 if(top)
1059 line(dest,x,y,x+15,y,c);
1060 rectfill(dest,x,y,x+3,y+15,c);
1061 rectfill(dest,x+12,y,x+15,y+15,c);
1062 rectfill(dest,x+4,y+2,x+11,y+5,c);
1063 rectfill(dest,x+4,y+10,x+11,y+13,c);
1064 }
1065
1066 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1067 {
1068 line(dest,x,y,x+15,y,c);
1069 }
1070
1071 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1072 {
1073 int32_t cx = COMBOX(pos);
1074 int32_t cy = COMBOY(pos);
1075
1076 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1077
1078 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1079
1080 int32_t bridgedetected = 0;
1081
1082 for(int32_t i=0; i<4; i++)
1083 {
1084 int32_t tx=((i&2)<<2)+x;
1085 int32_t ty=((i&1)<<3)+y;
1086 int32_t tx2=((i&2)<<2)+cx;
1087 int32_t ty2=((i&1)<<3)+cy;
1088 for (int32_t m = layer; m <= 1; m++)
1089 {
1090 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1091 {
1092 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1093 {
1094 bridgedetected |= (1<<i);
1095 }
1096 }
1097 else
1098 {
1099 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1100 {
1101 bridgedetected |= (1<<i);
1102 }
1103 }
1104 }
1105 if (bridgedetected & (1<<i))
1106 {
1107 if (i >= 3) break;
1108 else continue;
1109 }
1110 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1111 {
1112 for(int32_t k=0; k<8; k+=2)
1113 for(int32_t j=0; j<8; j+=2)
1114 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1115 }
1116 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1117 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1118
1119 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1120 {
1121 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1122 {
1123 for(int32_t k=0; k<8; k+=2)
1124 for(int32_t j=0; j<8; j+=2)
1125 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1126 }
1127 else
1128 {
1129 int32_t color = COLOR_SOLID;
1130
1131 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1132 color=vc(6);
1133 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1134 color=vc(7);
1135
1136 rectfill(dest,tx,ty,tx+7,ty+7,color);
1137 }
1138 }
1139 }
1140
1141 bridgedetected = 0;
1142 for(int32_t i=0; i<4; i++)
1143 {
1144 int32_t tx2=((i&2)<<2)+cx;
1145 int32_t ty2=((i&1)<<3)+cy;
1146 for (int32_t m = 0; m <= 1; m++)
1147 {
1148 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1149 {
1150 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1151 {
1152 bridgedetected |= (1<<i);
1153 }
1154 }
1155 else
1156 {
1157 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1158 {
1159 bridgedetected |= (1<<i);
1160 }
1161 }
1162 }
1163 }
1164
1165 // Draw damage combos
1166 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1167 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1168 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1169 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1170 || combo_class_buf[c1.type].modify_hp_amount
1171 || combo_class_buf[c2.type].modify_hp_amount;
1172
1173 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1174
1175 if(dmg)
1176 {
1177 if (bridgedetected <= 0)
1178 {
1179 for(int32_t k=0; k<16; k+=2)
1180 for(int32_t j=0; j<16; j+=2)
1181 if(((k+j)/2)%2)
1182 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1183 }
1184 else
1185 {
1186 for(int32_t i=0; i<4; i++)
1187 {
1188 if (!(bridgedetected & (1<<i)))
1189 {
1190 int32_t tx=((i&2)<<2)+x;
1191 int32_t ty=((i&1)<<3)+y;
1192 for(int32_t k=0; k<8; k+=2)
1193 for(int32_t j=0; j<8; j+=2)
1194 if(((k+j)/2)%2)
1195 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1196 }
1197 }
1198 }
1199 }
1200
1201 if(c.type == cSLOPE)
1202 {
1203 slope_info s(c, x, y);
1204 s.draw(dest, 0, 0, COLOR_SLOPE);
1205 }
1206 auto fl0 = MAPFLAG2(-1,cx,cy);
1207 auto fl1 = MAPFLAG2(0,cx,cy);
1208 auto fl2 = MAPFLAG2(1,cx,cy);
1209 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1210 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1211 {
1212 bool top = false;
1213 if(cy)
1214 {
1215 top = true;
1216 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1217 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1218 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1219 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1220 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1221 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1222 {
1223 top = false;
1224 }
1225 }
1226 draw_ladder(dest,x,y,COLOR_LADDER,top);
1227 }
1228 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1229 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1230 {
1231 draw_platform(dest,x,y,COLOR_LADDER);
1232 }
1233 }
1234
1235 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1236 {
1237 int32_t cx = COMBOX(pos);
1238 int32_t cy = COMBOY(pos);
1239
1240 if (screen < 0) return;
1241 if (map < 0) return;
1242
1243 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1244
1245 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1246
1247 int32_t bridgedetected = 0;
1248 for(int32_t i=0; i<4; i++)
1249 {
1250 int32_t tx=((i&2)<<2)+x;
1251 int32_t ty=((i&1)<<3)+y;
1252 int32_t tx2=((i&2)<<2)+cx;
1253 int32_t ty2=((i&1)<<3)+cy;
1254 for (int32_t m = layer; m <= 1; m++)
1255 {
1256 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1257 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1258 {
1259 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1260 {
1261 bridgedetected |= (1<<i);
1262 }
1263 }
1264 else
1265 {
1266 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1267 {
1268 bridgedetected |= (1<<i);
1269 }
1270 }
1271 }
1272 if (bridgedetected & (1<<i))
1273 {
1274 continue;
1275 }
1276 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1277 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1278
1279
1280 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1281 {
1282 for(int32_t k=0; k<8; k+=2)
1283 for(int32_t j=0; j<8; j+=2)
1284 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1285 }
1286 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1287 {
1288 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1289 {
1290 for(int32_t k=0; k<8; k+=2)
1291 for(int32_t j=0; j<8; j+=2)
1292 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1293 }
1294 else
1295 {
1296 int32_t color = COLOR_SOLID;
1297
1298 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1299 color=vc(6);
1300 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1301 color=vc(7);
1302
1303 rectfill(dest,tx,ty,tx+7,ty+7,color);
1304 }
1305 }
1306 }
1307
1308 bridgedetected = 0;
1309 for(int32_t i=0; i<4; i++)
1310 {
1311 int32_t tx2=((i&2)<<2)+cx;
1312 int32_t ty2=((i&1)<<3)+cy;
1313 for (int32_t m = 0; m <= 1; m++)
1314 {
1315 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1316 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1317 {
1318 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1319 {
1320 bridgedetected |= (1<<i);
1321 }
1322 }
1323 else
1324 {
1325 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1326 {
1327 bridgedetected |= (1<<i);
1328 }
1329 }
1330 }
1331 }
1332
1333 // Draw damage combos
1334 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1335 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1336 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1337 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1338 || combo_class_buf[c1.type].modify_hp_amount
1339 || combo_class_buf[c2.type].modify_hp_amount;
1340
1341 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1342
1343 if(dmg)
1344 {
1345 if (bridgedetected <= 0)
1346 {
1347 for(int32_t k=0; k<16; k+=2)
1348 for(int32_t j=0; j<16; j+=2)
1349 if(((k+j)/2)%2)
1350 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1351 }
1352 else
1353 {
1354 for(int32_t i=0; i<4; i++)
1355 {
1356 if (!(bridgedetected & (1<<i)))
1357 {
1358 int32_t tx=((i&2)<<2)+x;
1359 int32_t ty=((i&1)<<3)+y;
1360 for(int32_t k=0; k<8; k+=2)
1361 for(int32_t j=0; j<8; j+=2)
1362 if(((k+j)/2)%2)
1363 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1364 }
1365 }
1366 }
1367 }
1368
1369 if(c.type == cSLOPE)
1370 {
1371 slope_info s(c, x, y);
1372 s.draw(dest, 0, 0, COLOR_SLOPE);
1373 }
1374 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1375 auto fl1 = MAPFLAG3(map,screen,0,pos);
1376 auto fl2 = MAPFLAG3(map,screen,1,pos);
1377 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1378 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1379 {
1380 bool top = false;
1381 if(cy)
1382 {
1383 top = true;
1384 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1385 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1386 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1387 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1388 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1389 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1390 {
1391 top = false;
1392 }
1393 }
1394 draw_ladder(dest,x,y,COLOR_LADDER,top);
1395 }
1396 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1397 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1398 {
1399 draw_platform(dest,x,y,COLOR_LADDER);
1400 }
1401 }
1402
1403 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1404 {
1405 const newcombo& c = combobuf[cmbdat];
1406
1407 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1408
1409 for(int32_t i=0; i<4; i++)
1410 {
1411 int32_t tx=((i&2)<<2)+x;
1412 int32_t ty=((i&1)<<3)+y;
1413
1414 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1415 {
1416 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1417 {
1418 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1419 }
1420 else
1421 {
1422 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1423 }
1424 }
1425
1426
1427 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1428 {
1429 for(int32_t k=0; k<8; k+=2)
1430 for(int32_t j=0; j<8; j+=2)
1431 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1432 }
1433 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1434 {
1435 if(c.type==cLADDERHOOKSHOT)
1436 {
1437 for(int32_t k=0; k<8; k+=2)
1438 for(int32_t j=0; j<8; j+=2)
1439 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1440 }
1441 else
1442 {
1443 int32_t color = COLOR_SOLID;
1444
1445 if(c.type==cLADDERONLY)
1446 color=vc(6);
1447 else if(c.type==cHOOKSHOTONLY)
1448 color=vc(7);
1449
1450 rectfill(dest,tx,ty,tx+7,ty+7,color);
1451 }
1452 }
1453
1454 // Draw damage combos
1455 if(combo_class_buf[c.type].modify_hp_amount != 0)
1456 {
1457 for(int32_t k=0; k<8; k+=2)
1458 for(int32_t j=0; j<8; j+=2)
1459 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1460 }
1461 }
1462
1463 if(c.type == cSLOPE)
1464 {
1465 slope_info s(c, 0, 0);
1466 zfix const& slope = s.slope();
1467
1468 BITMAP* sub = create_bitmap_ex(8,16,16);
1469 clear_bitmap(sub);
1470 s.draw(sub, 0, 0, COLOR_SLOPE);
1471 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1472 destroy_bitmap(sub);
1473 }
1474 if(c.flag == mfSIDEVIEWLADDER)
1475 {
1476 draw_ladder(dest,x,y,COLOR_LADDER);
1477 }
1478 else if(c.flag == mfSIDEVIEWPLATFORM)
1479 {
1480 draw_platform(dest,x,y,COLOR_LADDER);
1481 }
1482 }
1483
1484 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1485 {
1486 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1487 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1488 }
1489 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1490 {
1491 newcombo const& c = combobuf[cmbdat];
1492
1493 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1494 {
1495 if(sflag)
1496 {
1497 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1498 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1499 }
1500
1501 if(c.flag)
1502 {
1503 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1504 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1505 }
1506 }
1507
1508 if(flags&cCSET)
1509 {
1510 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1511 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1512 }
1513 else if(flags&cCTYPE)
1514 {
1515 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1516 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1517 }
1518 }
1519
1520 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1521 {
1522 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1523
1524 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1525 if(repos)
1526 {
1527 combotile_override_x = x+(8*(scale-1));
1528 combotile_override_y = y+(8*(scale-1));
1529 }
1530 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1531 if(repos) combotile_override_x = combotile_override_y = -1;
1532 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1533 destroy_bitmap(b);
1534 }
1535 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1536 {
1537 static newcombo nilcombo;
1538 nilcombo.tile = 0;
1539
1540 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1541
1542 if(c.tile==0)
1543 {
1544 rectfill(dest,x,y,x+15,y+15,vc(0));
1545 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1546 return;
1547 }
1548
1549 putcombo(dest,x,y,cmbdat,cset);
1550
1551 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1552 {
1553 if(sflag)
1554 {
1555 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1556 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1557 }
1558
1559 if(combobuf[cmbdat].flag)
1560 {
1561 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1562 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1563 }
1564 }
1565
1566 if(flags&cWALK)
1567 {
1568 put_walkflags(dest,x,y,cmbdat,0);
1569 }
1570
1571 if(flags&cCSET)
1572 {
1573 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1574 // text_mode(inv?vc(15):vc(0));
1575 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1576 }
1577 else if(flags&cCTYPE)
1578 {
1579 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1580 // text_mode(inv?vc(15):vc(0));
1581 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1582 }
1583 }
1584 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1585 {
1586 auto blitx = 1 + (slot % 16) * 17;
1587 auto blity = 1 + (slot / 16) * 17;
1588 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1589 }
1590
1591
1592 void copy_mapscr(mapscr *dest, const mapscr *src)
1593 {
1594 if(!dest || !src) return;
1595 *dest = *src;
1596 }
1597
1598 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1599 {
1600 int32_t x=0,y=0;
1601 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1602
1603 switch(side)
1604 {
1605 case up:
1606 case down:
1607 x=((pos&15)<<4)+xofs;
1608 y=(ignorepos?0:(pos&0xF0))+yofs;
1609 break;
1610
1611 case left:
1612 case right:
1613 x=(ignorepos?0:((pos&15)<<4))+xofs;
1614 y=(pos&0xF0)+yofs;
1615 break;
1616 }
1617
1618 switch(type)
1619 {
1620 case dt_lock:
1621 case dt_shut:
1622 case dt_boss:
1623 case dt_bomb:
1624 switch(side)
1625 {
1626 case up:
1627 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1628 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1629 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1630 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1631 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1633 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1635 break;
1636
1637 case down:
1638 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1639 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1640 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1641 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1642 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1644 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1646 break;
1647
1648 case left:
1649 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1650 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1651 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1653 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1655
1656 if(x+16 >= dest->w)
1657 break;
1658
1659 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1660 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1661 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1663 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1665 break;
1666
1667 case right:
1668
1669 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1670 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1671 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1673 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1675
1676 if(x+16 <= 0)
1677 break;
1678
1679 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1680 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1681 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1682 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1683 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1684 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1685 break;
1686 }
1687
1688 break;
1689
1690 case dt_pass:
1691 case dt_wall:
1692 case dt_walk:
1693 default:
1694 break;
1695 }
1696 }
1697
1698 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1699 {
1700 int32_t x=((pos&15)<<4)+xofs;
1701 int32_t y=(pos&0xF0)+yofs;
1702 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1703
1704
1705 switch(side)
1706 {
1707 case up:
1708 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1709 {
1710 overcombo(dest,x,y,
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1712 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1713 }
1714
1715 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1716 {
1717 overcombo(dest,x+16,y,
1718 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1719
1720 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1721 }
1722
1723 break;
1724
1725 case down:
1726 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1727 {
1728 overcombo(dest,x,y,
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1730 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1731 }
1732
1733 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1734 {
1735 overcombo(dest,x+16,y,
1736 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1737 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1738 }
1739
1740 break;
1741
1742 case left:
1743 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1744 {
1745 overcombo(dest,x,y,
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1747 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1748 }
1749
1750 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1751 {
1752 overcombo(dest,x,y+16,
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1754 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1755 }
1756
1757 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1758 {
1759 overcombo(dest,x,y+32,
1760 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1761 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1762 }
1763
1764 break;
1765
1766 case right:
1767 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1768 {
1769 overcombo(dest,x,y,
1770 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1772 }
1773
1774 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1775 {
1776 overcombo(dest,x,y+16,
1777
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1779 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1780 }
1781
1782 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1783 {
1784 overcombo(dest,x,y+32,
1785 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1786 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1787 }
1788
1789 break;
1790 }
1791 }
1792
1793 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1794 {
1795 word cmbcheck1, cmbcheck2;
1796 newcombo combocheck1, combocheck2;
1797 combocheck1 = combobuf[0];
1798 combocheck2 = combobuf[0];
1799 combocheck1.walk = 0;
1800 combocheck2.walk = 0;
1801
1802 int32_t layermap, layerscreen;
1803
1804 switch(dir)
1805 {
1806 case up:
1807 {
1808 if(i>15) //not top row of combos
1809 {
1810 return false;
1811 }
1812
1813 if(screen<16) //top row of screens
1814 {
1815 return false;
1816
1817 }
1818
1819 //check main screen
1820 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1821 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1822 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1823 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1824
1825 //check layer 1
1826 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1827
1828 if(layermap>-1 && layermap<map_count)
1829 {
1830 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1831 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1832 if (combobuf[cmbcheck1].type == cBRIDGE)
1833 {
1834 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1835 {
1836 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1837 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1838 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1839 }
1840 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1841 }
1842 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1843 }
1844
1845 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1846
1847 if(layermap>-1 && layermap<map_count)
1848 {
1849 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1850 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1851 if (combobuf[cmbcheck2].type == cBRIDGE)
1852 {
1853 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1854 {
1855 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1856 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1857 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1858 }
1859 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1860 }
1861 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1862 }
1863
1864 //check layer 2
1865 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1866
1867 if(layermap>-1 && layermap<map_count)
1868 {
1869 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1870
1871 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1872 if (combobuf[cmbcheck2].type == cBRIDGE)
1873 {
1874 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1875 {
1876 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1877 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1878 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1879 }
1880 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1881 }
1882 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1883 }
1884
1885 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1886
1887 if(layermap>-1 && layermap<map_count)
1888 {
1889 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1890 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1891 if (combobuf[cmbcheck2].type == cBRIDGE)
1892 {
1893 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1894 {
1895 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1896 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1897 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1898 }
1899 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1900 }
1901 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1902 }
1903
1904 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1905 {
1906 return true;
1907 }
1908
1909 break;
1910 }
1911 case down:
1912 {
1913 if(i<160) //not bottom row of combos
1914 {
1915 return false;
1916 }
1917
1918 if(screen>111) //bottom row of screens
1919 {
1920 return false;
1921 }
1922
1923 //check main screen
1924 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1925 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1926 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1927 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1928
1929
1930 //check layer 1
1931 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1932
1933 if(layermap>-1 && layermap<map_count)
1934 {
1935 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1936 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1937 if (combobuf[cmbcheck1].type == cBRIDGE)
1938 {
1939 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1940 {
1941 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1942 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1943 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1944 }
1945 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1946 }
1947 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1948 }
1949
1950 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1951
1952 if(layermap>-1 && layermap<map_count)
1953 {
1954 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1955 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1956 if (combobuf[cmbcheck2].type == cBRIDGE)
1957 {
1958 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1959 {
1960 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1961 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1962 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1963 }
1964 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1965 }
1966 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1967 }
1968
1969 //check layer 2
1970 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1971
1972 if(layermap>-1 && layermap<map_count)
1973 {
1974 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1975 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1976 if (combobuf[cmbcheck1].type == cBRIDGE)
1977 {
1978 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1979 {
1980 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1981 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1982 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1983 }
1984 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1985 }
1986 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1987 }
1988
1989 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1990
1991 if(layermap>-1 && layermap<map_count)
1992 {
1993 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1994 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1995 if (combobuf[cmbcheck2].type == cBRIDGE)
1996 {
1997 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1998 {
1999 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2000 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2001 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2002 }
2003 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2004 }
2005 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2006 }
2007
2008 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2009 {
2010 return true;
2011 }
2012
2013 break;
2014 }
2015 case left:
2016 {
2017 if((i&0xF)!=0) //not left column of combos
2018 {
2019 return false;
2020 }
2021
2022 if((screen&0xF)==0) //left column of screens
2023 {
2024 return false;
2025 }
2026
2027 //check main screen
2028 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2029 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2030 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2031 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2032
2033 //check layer 1
2034 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2035
2036 if(layermap>-1 && layermap<map_count)
2037 {
2038 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2039 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2040 if (combobuf[cmbcheck1].type == cBRIDGE)
2041 {
2042 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2043 {
2044 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2045 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2046 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2047 }
2048 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2049 }
2050 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2051 }
2052
2053 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2054
2055 if(layermap>-1 && layermap<map_count)
2056 {
2057 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2058 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2059 if (combobuf[cmbcheck2].type == cBRIDGE)
2060 {
2061 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2062 {
2063 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2064 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2065 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2066 }
2067 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2068 }
2069 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2070 }
2071
2072 //check layer 2
2073 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2074
2075 if(layermap>-1 && layermap<map_count)
2076 {
2077 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2078 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2079 if (combobuf[cmbcheck1].type == cBRIDGE)
2080 {
2081 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2082 {
2083 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2084 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2085 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2086 }
2087 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2088 }
2089 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2090 }
2091
2092 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2093
2094 if(layermap>-1 && layermap<map_count)
2095 {
2096 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2097 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2098 if (combobuf[cmbcheck2].type == cBRIDGE)
2099 {
2100 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2101 {
2102 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2103 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2104 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2105 }
2106 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2107 }
2108 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2109 }
2110
2111 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2112 {
2113 return true;
2114 }
2115
2116 break;
2117 }
2118 case right:
2119 {
2120 if((i&0xF)!=15) //not right column of combos
2121 {
2122 return false;
2123 }
2124
2125 if((screen&0xF)==15) //right column of screens
2126 {
2127 return false;
2128 }
2129
2130 //check main screen
2131 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2132 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2133 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2134 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2135
2136 //check layer 1
2137 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2138
2139 if(layermap>-1 && layermap<map_count)
2140 {
2141 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2142 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2143 if (combobuf[cmbcheck1].type == cBRIDGE)
2144 {
2145 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2146 {
2147 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2148 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2149 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2150 }
2151 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2152 }
2153 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2154 }
2155
2156 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2157
2158 if(layermap>-1 && layermap<map_count)
2159 {
2160 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2161 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2162 if (combobuf[cmbcheck2].type == cBRIDGE)
2163 {
2164 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2165 {
2166 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2167 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2168 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2169 }
2170 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2171 }
2172 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2173 }
2174
2175 //check layer 2
2176 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2177
2178 if(layermap>-1 && layermap<map_count)
2179 {
2180 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2181 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2182 if (combobuf[cmbcheck1].type == cBRIDGE)
2183 {
2184 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2185 {
2186 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2187 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2188 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2189 }
2190 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2191 }
2192 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2193 }
2194
2195 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2196
2197 if(layermap>-1 && layermap<map_count)
2198 {
2199 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2200
2201 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2202 if (combobuf[cmbcheck2].type == cBRIDGE)
2203 {
2204 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2205 {
2206 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2207 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2208 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2209 }
2210 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2211 }
2212 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2213 }
2214
2215 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2216 {
2217 return true;
2218 }
2219
2220 break;
2221 }
2222 }
2223
2224 return false;
2225 }
2226
2227 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2228 {
2229 int32_t checkcombo;
2230
2231 if(alignment_arrow_timer>31)
2232 {
2233 if(scr<0)
2234 {
2235 scr=cursor.screen;
2236 }
2237
2238 if((scr<128)) //do the misalignment arrows
2239 {
2240 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2241 {
2242 if(misaligned(cursor.map, scr, checkcombo, up))
2243 {
2244 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2245 }
2246 }
2247
2248 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2249 {
2250 if(misaligned(cursor.map, scr, checkcombo, down))
2251 {
2252 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2253 }
2254 }
2255
2256 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2257 {
2258 if(misaligned(cursor.map, scr, checkcombo, left))
2259 {
2260 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2261 }
2262 }
2263
2264 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2265 {
2266 if(misaligned(cursor.map, scr, checkcombo, right))
2267 {
2268 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2269 }
2270 }
2271
2272 int32_t tempalign;
2273
2274 //check top left corner
2275 checkcombo=0;
2276 tempalign=0;
2277 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2278 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2279
2280 switch(tempalign)
2281 {
2282 case 0:
2283 break;
2284
2285 case 1: //up
2286 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2287 break;
2288
2289 case 2: //left
2290 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2291 break;
2292
2293 case 3: //up-left
2294 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2295 break;
2296 }
2297
2298 //check top right corner
2299 checkcombo=15;
2300 tempalign=0;
2301 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2302 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2303
2304 switch(tempalign)
2305 {
2306 case 0:
2307 break;
2308
2309 case 1: //up
2310 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2311 break;
2312
2313 case 2: //right
2314 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2315 break;
2316
2317 case 3: //up-right
2318 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2319 break;
2320 }
2321
2322 //check bottom left corner
2323 checkcombo=160;
2324 tempalign=0;
2325 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2326 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2327
2328 switch(tempalign)
2329 {
2330 case 0:
2331 break;
2332
2333 case 1: //down
2334 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2335 break;
2336
2337 case 2: //left
2338 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2339 break;
2340
2341 case 3: //down-left
2342 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2343 break;
2344 }
2345
2346 //check bottom right corner
2347
2348 checkcombo=175;
2349 tempalign=0;
2350 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2351 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2352
2353 switch(tempalign)
2354 {
2355 case 0:
2356 break;
2357
2358 case 1: //down
2359 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2360 break;
2361
2362 case 2: //right
2363 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2364 break;
2365
2366 case 3: //down-right
2367 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2368 break;
2369 }
2370 }
2371 }
2372 }
2373
2374 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2375 {
2376 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2377 }
2378
2379 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2380 {
2381 if (map < 0 || screen < 0) return 0;
2382
2383 if(pos>175 || pos < 0)
2384 return 0;
2385
2386 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2387
2388 if (!m->is_valid()) return 0;
2389
2390 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2391
2392 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2393
2394 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2395
2396 if (!scr->is_valid()) return 0;
2397
2398 return scr->data[pos]; // entire combo code
2399 }
2400
2401 // Takes array index layer num., not actual layer num.
2402 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2403 {
2404 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2405
2406 if(map<0)
2407 map=cursor.map;
2408
2409 if(scr<0)
2410 scr=cursor.screen;
2411
2412 mapscr *screen1;
2413
2414 if(prv_mode)
2415 {
2416 screen1=get_prvscr();
2417 }
2418 else
2419 {
2420 screen1=AbsoluteScr(cursor.map,cursor.screen);
2421 }
2422
2423 int32_t layermap;
2424 layermap=screen1->layermap[lyr]-1;
2425
2426 if(layermap<0 || layermap >= map_count) return 0;
2427
2428 mapscr *layer;
2429
2430 if(prv_mode)
2431 layer = &prvlayers[lyr];
2432 else
2433 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2434
2435 int32_t pos = COMBOPOS(x,y);
2436
2437 if(pos>175 || pos < 0)
2438 return 0;
2439
2440 return layer->data[pos];
2441 }
2442
2443 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2444 {
2445 if(map<0)
2446 map=cursor.map;
2447
2448 if(scr<0)
2449 scr=cursor.screen;
2450
2451 mapscr *screen1;
2452
2453 if(prv_mode)
2454 {
2455 screen1=get_prvscr();
2456 }
2457 else
2458 {
2459 screen1=AbsoluteScr(cursor.map,cursor.screen);
2460 }
2461
2462 x = vbound(x, 0, 16*16);
2463 y = vbound(y, 0, 11*16);
2464 int32_t combo = COMBOPOS(x,y);
2465
2466 if(combo>175 || combo < 0)
2467 return 0;
2468
2469 return screen1->data[combo];
2470 }
2471
2472 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2473 {
2474 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2475 }
2476
2477 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2478 {
2479 if (map < 0 || screen < 0) return 0;
2480
2481 if(pos>175 || pos < 0)
2482 return 0;
2483
2484 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2485
2486 if (!m->is_valid()) return 0;
2487
2488 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2489
2490 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2491
2492 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2493
2494 if (!scr->is_valid()) return 0;
2495
2496 return scr->sflag[pos]; // entire combo code
2497 }
2498
2499 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2500 {
2501 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2502
2503 if(map<0)
2504 map=cursor.map;
2505
2506 if(scr<0)
2507 scr=cursor.screen;
2508
2509 mapscr *screen1;
2510
2511 if(prv_mode)
2512 {
2513 screen1=get_prvscr();
2514 }
2515 else
2516 {
2517 screen1=AbsoluteScr(cursor.map,cursor.screen);
2518 }
2519
2520 int32_t layermap;
2521 layermap=screen1->layermap[lyr]-1;
2522
2523 if(layermap<0 || layermap >= map_count) return 0;
2524
2525 mapscr *layer;
2526
2527 if(prv_mode)
2528 layer = &prvlayers[lyr];
2529 else
2530 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2531
2532 int32_t combo = COMBOPOS(x,y);
2533
2534 if(combo>175 || combo < 0)
2535 return 0;
2536
2537 return layer->sflag[combo];
2538 }
2539
2540 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2541 {
2542 if(map<0)
2543 map=cursor.map;
2544
2545 if(scr<0)
2546 scr=cursor.screen;
2547
2548 mapscr *screen1;
2549
2550 if(prv_mode)
2551 {
2552 screen1=get_prvscr();
2553 }
2554 else
2555 {
2556 screen1=AbsoluteScr(cursor.map,cursor.screen);
2557 }
2558
2559 x = vbound(x, 0, 16*16);
2560 y = vbound(y, 0, 11*16);
2561 int32_t combo = COMBOPOS(x,y);
2562
2563 if(combo>175 || combo < 0)
2564 return 0;
2565
2566 return screen1->sflag[combo];
2567 }
2568
2569 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2570 {
2571 mapscr *layers[7];
2572 mapscr *basescr;
2573 if(prv_mode)
2574 {
2575 layers[0] = &prvscr;
2576 basescr = layers[0];
2577 for(auto q = 1; q < 7; ++q)
2578 {
2579 if(prvlayers[q-1].valid)
2580 layers[q] = &(prvlayers[q-1]);
2581 else layers[q] = NULL;
2582 }
2583 }
2584 else
2585 {
2586 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2587 basescr = layers[0];
2588 for(auto q = 1; q < 7; ++q)
2589 {
2590 int32_t lmap = basescr->layermap[q-1]-1;
2591 int32_t lscr = basescr->layerscreen[q-1];
2592 if(lmap < 0)
2593 layers[q] = NULL;
2594 else layers[q] = AbsoluteScr(lmap, lscr);
2595 }
2596 }
2597 for(auto q = 0; q < 7; ++q)
2598 {
2599 if(!layers[q]) continue;
2600 for(auto pos = 0; pos < 176; ++pos)
2601 {
2602 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2603 if(cmb.type == cTORCH)
2604 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2605 }
2606 }
2607 word maxffc = basescr->numFFC();
2608 for(auto q = 0; q < maxffc; ++q)
2609 {
2610 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2611 if(cmb.type == cTORCH)
2612 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2613 }
2614 }
2615
2616 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2617 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2618 {
2619 newcombo const& cmb = combobuf[cid];
2620 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2621 if(dither)
2622 {
2623 if (LayerDitherSz == 0)
2624 return;
2625 BITMAP* buf = create_bitmap_ex(8,16,16);
2626 clear_bitmap(buf);
2627 overcombo(buf,0,0,cid,cset);
2628 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2629 if(over)
2630 {
2631 if(transp)
2632 {
2633 color_map = trans_table2;
2634 draw_trans_sprite(dest, buf, x, y);
2635 color_map = trans_table;
2636 }
2637 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2638 }
2639 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2640 destroy_bitmap(buf);
2641 }
2642 else if(over)
2643 {
2644 if(transp)
2645 overcombotranslucent(dest,x,y,cid,cset,0);
2646 else overcombo(dest,x,y,cid,cset);
2647 }
2648 else put_combo(dest,x,y,cid,cset,flags,sflag);
2649 }
2650 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2651 {
2652 if(!md) return;
2653
2654 // These should only be drawn for the currently selected layer, not every layer.
2655 SETFLAG(flags, cCSET, false);
2656 SETFLAG(flags, cCTYPE, false);
2657
2658 for (int32_t i = 0; i < 176; i++)
2659 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2660 }
2661 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2662 {
2663 if(!md) return;
2664
2665 // These should only be drawn for the currently selected layer, not every layer.
2666 SETFLAG(flags, cCSET, false);
2667 SETFLAG(flags, cCTYPE, false);
2668
2669 for (int32_t i = 0; i < 176; i++)
2670 {
2671 int data = md->data[i];
2672 if(combo_class_buf[combobuf[data].type].overhead)
2673 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2674 }
2675 }
2676 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2677 {
2678 if(!LayerMaskInt[lyr])
2679 return nullptr;
2680 if(lyr == 0)
2681 return basescr;
2682 int layermap = basescr->layermap[lyr-1]-1;
2683
2684 if(layermap>-1 && layermap<map_count)
2685 {
2686 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2687 return &TheMaps[layerscreen];
2688 }
2689 return nullptr;
2690 }
2691 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2692 {
2693 int num_ffcs = basescr->numFFC();
2694 for(int32_t i=num_ffcs-1; i>=0; i--)
2695 {
2696 auto const& ff = basescr->ffcs[i];
2697 if(ff.data)
2698 {
2699 if(!(ff.flags&ffc_changer))
2700 {
2701 int32_t tx=(ff.x.getInt())+x;
2702 int32_t ty=(ff.y.getInt())+y;
2703
2704 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2705 {
2706 if(ff.flags&ffc_trans)
2707 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2708 else
2709 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2710 }
2711 }
2712 }
2713 }
2714 }
2715 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2716 {
2717 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2718 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2719 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
2720
2721 if(map<0)
2722 map=cursor.map;
2723
2724 if(screen<0)
2725 screen=cursor.screen;
2726
2727 mapscr *basescr;
2728 mapscr* layers[7] = {nullptr};
2729
2730 if(prv_mode)
2731 {
2732 hl_layer = -1;
2733 basescr=get_prvscr();
2734 }
2735 else
2736 {
2737 basescr=AbsoluteScr(map,screen);
2738 }
2739 layers[0] = _zmap_get_lyr_checked(0,basescr);
2740 for(int lyr = 1; lyr < 7; ++lyr)
2741 {
2742 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2743 : _zmap_get_lyr_checked(lyr,basescr);
2744 }
2745
2746 if(!(basescr->valid&mVALID))
2747 {
2748 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2749 rectfill(dest,x,y,x+255,y+175,vc(1));
2750
2751 if(ShowMisalignments)
2752 {
2753 check_alignments(dest,x,y,screen);
2754 }
2755
2756 return;
2757 }
2758
2759 if(LayerMaskInt[0]==0 || !get_qr(qr_CLASSIC_DRAWING_ORDER))
2760 {
2761 byte bgfill = 0;
2762 if (LayerDitherBG > -1)
2763 bgfill = vc(LayerDitherBG);
2764 rectfill(dest,x,y,x+255,y+175,bgfill);
2765 }
2766
2767 if(olddraw)
2768 {
2769 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2770 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2771 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2772 }
2773 else for (int lyr = -7; lyr < -3; ++lyr)
2774 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, lyr);
2775
2776 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2777 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2778 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2779
2780 if(!olddraw)
2781 {
2782 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2783 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2784 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2785 }
2786 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2787
2788 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !olddraw || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2789 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2790
2791
2792 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2793 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2794
2795 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2796 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2797 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2798
2799 struct DoorDrawData
2800 {
2801 int over_pos; // Position for over_door (dBOMB)
2802 int put_pos; // Position for put_door (standard doors)
2803 int walk_x; // Pre-calculated X offset for dWALK
2804 int walk_y; // Pre-calculated Y offset for dWALK
2805 };
2806
2807 static const DoorDrawData door_data[4] = {
2808 // over, put, walk_x, walk_y
2809 { 39, 7, 120, 16 }, // up
2810 { 135, 151, 120, 144 }, // down
2811 { 66, 64, 16, 80 }, // left
2812 { 77, 78, 224, 80 } // right
2813 };
2814
2815 auto door_set = DoorComboSets[screens[cursor.screen].door_combo_set];
2816 bool walk_trans = get_bit(door_set.flags, df_walktrans);
2817
2818 int32_t doortype[4];
2819 for(int32_t i=0; i<4; i++)
2820 {
2821 switch(basescr->door[i])
2822 {
2823 case dOPEN: doortype[i]=dt_pass; break;
2824 case dLOCKED: doortype[i]=dt_lock; break;
2825 case d1WAYSHUTTER:
2826 case dSHUTTER: doortype[i]=dt_shut; break;
2827 case dBOSS: doortype[i]=dt_boss; break;
2828 case dBOMB: doortype[i]=dt_bomb; break;
2829 default: doortype[i]=0; // Default or unhandled
2830 }
2831 }
2832
2833 for (int i = 0; i < 4; ++i)
2834 {
2835 const auto& d = door_data[i];
2836 const int current_door_type_id = basescr->door[i];
2837
2838 switch (current_door_type_id) {
2839 case dBOMB:
2840 // Draw bombable overlay, then fall through to draw the door
2841 over_door(dest, d.over_pos, i, x, y, false, screen);
2842 [[fallthrough]];
2843
2844 case dOPEN:
2845 case dLOCKED:
2846 case d1WAYSHUTTER:
2847 case dSHUTTER:
2848 case dBOSS:
2849 {
2850 put_door(dest, d.put_pos, i, doortype[i], x, y, false, screen);
2851 break;
2852 }
2853
2854 case dWALK:
2855 if (walk_trans) {
2856 overcombo(dest, d.walk_x + x, d.walk_y + y,
2857 door_set.walkthroughcombo[i],
2858 door_set.walkthroughcset[i]);
2859 } else {
2860 put_combo(dest, d.walk_x + x, d.walk_y + y,
2861 door_set.walkthroughcombo[i],
2862 door_set.walkthroughcset[i], 0, 0);
2863 }
2864 break;
2865 }
2866 }
2867
2868 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2869 {
2870 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2871 }
2872
2873 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2874 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2875 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2876
2877 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2878 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2879
2880 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2881
2882 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2883 {
2884 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2885 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2886 }
2887 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2888 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2889
2890 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2891
2892 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2893 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2894 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2895
2896 int num_ffcs = basescr->numFFC();
2897 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2898 if(basescr->ffcs[i].data)
2899 if(basescr->ffcs[i].flags&ffc_changer)
2900 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2901
2902 if(flags&cWALK)
2903 {
2904 if(layers[0])
2905 for(int32_t i=0; i<176; i++)
2906 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2907
2908 for(int32_t k=0; k<2; k++)
2909 {
2910 if(layers[k+1])
2911 for(int32_t i=0; i<176; i++)
2912 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2913 }
2914 for(int32_t i=num_ffcs-1; i>=0; i--)
2915 {
2916 if(auto data = basescr->ffcs[i].data)
2917 {
2918 if(!(basescr->ffcs[i].flags&ffc_changer))
2919 {
2920 newcombo const& cmb = combobuf[data];
2921 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2922 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2923
2924 if(basescr->ffcs[i].flags&ffc_solid)
2925 {
2926 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2927 }
2928
2929 if(cmb.type == cSLOPE)
2930 {
2931 slope_info s(cmb, tx, ty);
2932 s.draw(dest, 0, 0, COLOR_SLOPE);
2933 }
2934 }
2935 }
2936 }
2937 }
2938
2939 if(flags&(cFLAGS|cCSET|cCTYPE))
2940 {
2941 if(LayerMaskInt[CurrentLayer]!=0)
2942 {
2943 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2944 auto* scr = _lscr>-1 && _lscr<map_count*MAPSCRS ? &TheMaps[_lscr] : nullptr;
2945
2946 for(int32_t i=0; i<176; i++)
2947 {
2948 if(CurrentLayer==0)
2949 {
2950 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2951 }
2952 else
2953 {
2954 if(prv_mode)
2955 {
2956 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2957 }
2958 else if(basescr->layermap[CurrentLayer-1] > 0)
2959 {
2960 if(scr)
2961 {
2962 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2963 scr->data[i],
2964 scr->cset[i], flags,
2965 scr->sflag[i]);
2966 }
2967 }
2968 }
2969 }
2970 }
2971 }
2972
2973 int32_t dark = basescr->flags&cDARK;
2974
2975 if(dark && !(flags&cNODARK)
2976 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2977 {
2978 int col = vc(blackout_color);
2979 for(int32_t j=0; j<80; j++) {
2980 // Logic: ((i^j)&1)==0 means parity matches
2981 int start = (j&1);
2982 for(int32_t i=start; i<(80)-j; i+=2) {
2983 putpixel(dest,x+i,y+j,col);
2984 }
2985 }
2986 }
2987
2988 if(ShowMisalignments)
2989 {
2990 check_alignments(dest,x,y,screen);
2991 }
2992 }
2993
2994 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
2995 {
2996 if(map<0)
2997 map=cursor.map;
2998
2999 if(scr<0)
3000 scr=cursor.screen;
3001
3002 mapscr* layer=AbsoluteScr(map,scr);
3003 int32_t layermap=0, layerscreen=0;
3004
3005 if(!(layer->valid&mVALID))
3006 {
3007 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3008 rectfill(dest,x,y,x+255,y+15,vc(1));
3009 return;
3010 }
3011
3012 int32_t dark = layer->flags&4;
3013
3014 if(LayerMaskInt[0]==0)
3015 {
3016 rectfill(dest,x,y,x+255,y+15,0);
3017 }
3018
3019 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3020 int order[2] = {2,1};
3021 if (olddraw) zc_swap(order[0],order[1]);
3022 for(int k : order)
3023 {
3024 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3025 {
3026 layermap=layer->layermap[k]-1;
3027
3028 if(layermap>-1 && layermap<map_count)
3029 {
3030 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3031
3032 for(int32_t i=c; i<(c&0xF0)+16; i++)
3033 {
3034 auto data = TheMaps[layerscreen].data[i];
3035 auto cs = TheMaps[layerscreen].cset[i];
3036 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3037 }
3038 }
3039 }
3040 }
3041
3042 if(LayerMaskInt[0]!=0)
3043 {
3044 for(int32_t i=c; i<(c&0xF0)+16; i++)
3045 {
3046 word cmbdat = (i < 176 ? layer->data[i] : 0);
3047 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3048 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3049 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3050 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3051 }
3052 }
3053
3054 for(int32_t k=0; k<2; k++)
3055 {
3056 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3057 {
3058 layermap=layer->layermap[k]-1;
3059
3060 if(layermap>-1 && layermap<map_count)
3061 {
3062 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3063
3064 for(int32_t i=c; i<(c&0xF0)+16; i++)
3065 {
3066 auto data = TheMaps[layerscreen].data[i];
3067 auto cs = TheMaps[layerscreen].cset[i];
3068 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3069 }
3070 }
3071 }
3072 }
3073
3074 int32_t doortype[4];
3075
3076 for(int32_t i=0; i<4; i++)
3077 {
3078 switch(layer->door[i])
3079 {
3080 case dOPEN:
3081 doortype[i]=dt_pass;
3082 break;
3083
3084 case dLOCKED:
3085 doortype[i]=dt_lock;
3086 break;
3087
3088 case d1WAYSHUTTER:
3089 case dSHUTTER:
3090 doortype[i]=dt_shut;
3091 break;
3092
3093 case dBOSS:
3094 doortype[i]=dt_boss;
3095 break;
3096
3097 case dBOMB:
3098 doortype[i]=dt_bomb;
3099 break;
3100 }
3101 }
3102
3103 if(c<16)
3104 {
3105 switch(layer->door[up])
3106 {
3107 case dBOMB:
3108 case dOPEN:
3109 case dLOCKED:
3110 case d1WAYSHUTTER:
3111 case dSHUTTER:
3112 case dBOSS:
3113 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3114 break;
3115 }
3116 }
3117 else if(c>159)
3118 {
3119 switch(layer->door[down])
3120 {
3121 case dBOMB:
3122 case dOPEN:
3123 case dLOCKED:
3124 case d1WAYSHUTTER:
3125 case dSHUTTER:
3126 case dBOSS:
3127 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3128 break;
3129 }
3130 }
3131
3132 for(int32_t k=2; k<4; k++)
3133 {
3134 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3135 {
3136 layermap=layer->layermap[k]-1;
3137
3138 if(layermap>-1 && layermap<map_count)
3139 {
3140 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3141
3142 for(int32_t i=c; i<(c&0xF0)+16; i++)
3143 {
3144 if(layer->layeropacity[k]<255)
3145 {
3146 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3147 }
3148 else
3149 {
3150 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3151 }
3152 }
3153 }
3154 }
3155 }
3156
3157 //Overhead L0
3158 if(LayerMaskInt[0]!=0)
3159 {
3160 for(int32_t i=c; i<(c&0xF0)+16; i++)
3161 {
3162 int32_t ct1=layer->data[i];
3163 int32_t ct3=combobuf[ct1].type;
3164
3165 if(combo_class_buf[ct3].overhead)
3166 {
3167 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3168 }
3169 }
3170 }
3171
3172 //Overhead L1/2
3173 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3174 {
3175 for(int32_t k = 0; k < 2; ++k)
3176 {
3177 if(LayerMaskInt[k+1]!=0)
3178 {
3179 layermap=layer->layermap[k]-1;
3180
3181 if(layermap>-1 && layermap<map_count)
3182 {
3183 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3184 for(int32_t i=c; i<(c&0xF0)+16; i++)
3185 {
3186 auto data = TheMaps[layerscreen].data[i];
3187 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3188 auto cs = TheMaps[layerscreen].cset[i];
3189 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3190 }
3191 }
3192 }
3193 }
3194 }
3195
3196 for(int32_t k=4; k<6; k++)
3197 {
3198 if(LayerMaskInt[k+1]!=0)
3199 {
3200 layermap=layer->layermap[k]-1;
3201
3202 if(layermap>-1 && layermap<map_count)
3203 {
3204 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3205
3206 for(int32_t i=c; i<(c&0xF0)+16; i++)
3207 {
3208 auto data = TheMaps[layerscreen].data[i];
3209 auto cs = TheMaps[layerscreen].cset[i];
3210 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3211 }
3212 }
3213 }
3214 }
3215
3216 if(flags&cWALK)
3217 {
3218 if(LayerMaskInt[0]!=0)
3219 {
3220 for(int32_t i=c; i<(c&0xF0)+16; i++)
3221 {
3222 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3223 }
3224 }
3225
3226 for(int32_t k=0; k<2; k++)
3227 {
3228 if(LayerMaskInt[k+1]!=0)
3229 {
3230 for(int32_t i=c; i<(c&0xF0)+16; i++)
3231 {
3232 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3233 }
3234 }
3235 }
3236 }
3237
3238 if(flags&(cFLAGS|cCSET|cCTYPE))
3239 {
3240 if(LayerMaskInt[CurrentLayer]!=0)
3241 {
3242 for(int32_t i=c; i<(c&0xF0)+16; i++)
3243 {
3244 if(CurrentLayer==0)
3245 {
3246 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3247 }
3248 else
3249 {
3250 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3251
3252 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3253 {
3254 if(i < 176)
3255 {
3256 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3257 TheMaps[_lscr].data[i],
3258 TheMaps[_lscr].cset[i], flags|dark,
3259 TheMaps[_lscr].sflag[i]);
3260 }
3261 else
3262 {
3263 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3264 }
3265 }
3266 }
3267 }
3268 }
3269
3270 /*
3271 if (LayerMaskInt[0]!=0) {
3272 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3273 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3274 }
3275 }
3276 */
3277 }
3278
3279 if(ShowMisalignments)
3280 {
3281 if(c<16)
3282 {
3283 check_alignments(dest,x,y,scr);
3284 }
3285 else if(c>159)
3286 {
3287 check_alignments(dest,x,y-160,scr);
3288 }
3289 }
3290 }
3291
3292 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3293 {
3294 if(map<0)
3295 map=cursor.map;
3296
3297 if(scr<0)
3298 scr=cursor.screen;
3299
3300 mapscr* layer=AbsoluteScr(map,scr);
3301 int32_t layermap=0, layerscreen=0;
3302
3303 if(!(layer->valid&mVALID))
3304 {
3305 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3306 rectfill(dest,x,y,x+15,y+175,vc(1));
3307 return;
3308 }
3309
3310 int32_t dark = layer->flags&4;
3311
3312 if(LayerMaskInt[0]==0)
3313 {
3314 rectfill(dest,x,y,x+15,y+175,0);
3315 }
3316
3317 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3318 int order[2] = {2,1};
3319 if (olddraw) zc_swap(order[0],order[1]);
3320 for(int k : order)
3321 {
3322 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3323 {
3324 layermap=layer->layermap[k]-1;
3325
3326 if(layermap>-1 && layermap<map_count)
3327 {
3328 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3329
3330 for(int32_t i=c; i<176; i+=16)
3331 {
3332 auto data = TheMaps[layerscreen].data[i];
3333 auto cs = TheMaps[layerscreen].cset[i];
3334 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3335 }
3336 }
3337 }
3338 }
3339
3340 if(LayerMaskInt[0]!=0)
3341 {
3342 for(int32_t i=c; i<176; i+=16)
3343 {
3344 word cmbdat = layer->data[i];
3345 byte cmbcset = layer->cset[i];
3346 int32_t cmbflag = layer->sflag[i];
3347 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3348 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3349 }
3350 }
3351
3352 for(int32_t k=0; k<2; k++)
3353 {
3354 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3355 {
3356 layermap=layer->layermap[k]-1;
3357
3358 if(layermap>-1 && layermap<map_count)
3359 {
3360 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3361
3362 for(int32_t i=c; i<176; i+=16)
3363 {
3364 auto data = TheMaps[layerscreen].data[i];
3365 auto cs = TheMaps[layerscreen].cset[i];
3366 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3367 }
3368 }
3369 }
3370 }
3371
3372 int32_t doortype[4];
3373
3374 for(int32_t i=0; i<4; i++)
3375 {
3376 switch(layer->door[i])
3377 {
3378 case dOPEN:
3379 doortype[i]=dt_pass;
3380 break;
3381
3382 case dLOCKED:
3383 doortype[i]=dt_lock;
3384 break;
3385
3386 case d1WAYSHUTTER:
3387 case dSHUTTER:
3388 doortype[i]=dt_shut;
3389 break;
3390
3391 case dBOSS:
3392 doortype[i]=dt_boss;
3393 break;
3394
3395 case dBOMB:
3396 doortype[i]=dt_bomb;
3397 break;
3398 }
3399 }
3400
3401 if((c&0x0F)==0)
3402 {
3403 switch(layer->door[left])
3404 {
3405
3406 case dBOMB:
3407 case dOPEN:
3408 case dLOCKED:
3409 case d1WAYSHUTTER:
3410 case dSHUTTER:
3411 case dBOSS:
3412 // put_door(dest,64,left,doortype[left],x+256,y,true);
3413 put_door(dest,64,left,doortype[left],x,y,true,scr);
3414 break;
3415 }
3416 }
3417 else if((c&0x0F)==15)
3418 {
3419 switch(layer->door[right])
3420 {
3421 case dBOMB:
3422 case dOPEN:
3423 case dLOCKED:
3424 case d1WAYSHUTTER:
3425 case dSHUTTER:
3426 case dBOSS:
3427 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3428 break;
3429 }
3430 }
3431
3432 for(int32_t k=2; k<4; k++)
3433 {
3434 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3435 {
3436 layermap=layer->layermap[k]-1;
3437
3438 if(layermap>-1 && layermap<map_count)
3439 {
3440 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3441
3442 for(int32_t i=c; i<176; i+=16)
3443 {
3444 auto data = TheMaps[layerscreen].data[i];
3445 auto cs = TheMaps[layerscreen].cset[i];
3446 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3447 }
3448 }
3449 }
3450 }
3451
3452 //Overhead L0
3453 if(LayerMaskInt[0]!=0)
3454 {
3455 for(int32_t i=c; i<176; i+=16)
3456 {
3457 auto data = TheMaps[layerscreen].data[i];
3458 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3459 auto cs = TheMaps[layerscreen].cset[i];
3460 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3461 }
3462 }
3463 //Overhead L1/2
3464 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3465 {
3466 for(int32_t k = 0; k < 2; ++k)
3467 {
3468 if(LayerMaskInt[k+1]!=0)
3469 {
3470 layermap=layer->layermap[k]-1;
3471
3472 if(layermap>-1 && layermap<map_count)
3473 {
3474 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3475 for(int32_t i=c; i<176; i+=16)
3476 {
3477 auto data = TheMaps[layerscreen].data[i];
3478 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3479 auto cs = TheMaps[layerscreen].cset[i];
3480 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3481 }
3482 }
3483 }
3484 }
3485 }
3486
3487
3488 for(int32_t k=4; k<6; k++)
3489 {
3490 if(LayerMaskInt[k+1]!=0)
3491 {
3492 layermap=layer->layermap[k]-1;
3493
3494 if(layermap>-1 && layermap<map_count)
3495 {
3496 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3497
3498 for(int32_t i=c; i<176; i+=16)
3499 {
3500 auto data = TheMaps[layerscreen].data[i];
3501 auto cs = TheMaps[layerscreen].cset[i];
3502 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3503 }
3504 }
3505 }
3506 }
3507
3508 if(flags&cWALK)
3509 {
3510 if(LayerMaskInt[0]!=0)
3511 {
3512 for(int32_t i=c&0xF; i<176; i+=16)
3513 {
3514 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3515 }
3516 }
3517
3518 for(int32_t k=0; k<2; k++)
3519 {
3520 if(LayerMaskInt[k+1]!=0)
3521 {
3522 for(int32_t i=c&0xF; i<176; i+=16)
3523 {
3524 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3525 }
3526 }
3527 }
3528 }
3529
3530 if(flags&(cFLAGS|cCSET|cCTYPE))
3531 {
3532 if(LayerMaskInt[CurrentLayer]!=0)
3533 {
3534 for(int32_t i=c; i<176; i+=16)
3535 {
3536 if(CurrentLayer==0)
3537 {
3538 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3539 }
3540 else
3541 {
3542 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3543
3544 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3545 {
3546 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3547 TheMaps[_lscr].data[i],
3548 TheMaps[_lscr].cset[i], flags|dark,
3549 TheMaps[_lscr].sflag[i]);
3550 }
3551 }
3552 }
3553 }
3554 }
3555
3556 if(ShowMisalignments)
3557 {
3558 if((c&0x0F)==0)
3559 {
3560 check_alignments(dest,x,y,scr);
3561 }
3562 else if((c&0x0F)==15)
3563 {
3564 check_alignments(dest,x-240,y,scr);
3565 }
3566 }
3567 }
3568
3569 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3570 {
3571 if(map<0)
3572 map=cursor.map;
3573
3574 if(scr<0)
3575 scr=cursor.screen;
3576
3577 mapscr* layer=AbsoluteScr(map,scr);
3578 int32_t layermap=0, layerscreen=0;
3579
3580 if(!(layer->valid&mVALID))
3581 {
3582 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3583 rectfill(dest,x,y,x+15,y+15,vc(1));
3584 return;
3585 }
3586
3587 int32_t dark = layer->flags&4;
3588
3589 if(LayerMaskInt[0]!=0)
3590 {
3591 rectfill(dest,x,y,x+15,y+15,0);
3592 }
3593
3594 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3595 int order[2] = {2,1};
3596 if (olddraw) zc_swap(order[0],order[1]);
3597 for(int k : order)
3598 {
3599 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3600 {
3601 layermap=layer->layermap[k]-1;
3602
3603 if(layermap>-1 && layermap<map_count)
3604 {
3605 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3606
3607 auto data = TheMaps[layerscreen].data[c];
3608 auto cs = TheMaps[layerscreen].cset[c];
3609 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3610 }
3611 }
3612 }
3613
3614 if(LayerMaskInt[0]!=0)
3615 {
3616 word cmbdat = layer->data[c];
3617 byte cmbcset = layer->cset[c];
3618 int32_t cmbflag = layer->sflag[c];
3619 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3620 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3621 }
3622
3623
3624 for(int32_t k=0; k<2; k++)
3625 {
3626 if(LayerMaskInt[k+1]!=0)
3627 {
3628 layermap=layer->layermap[k]-1;
3629
3630 if(layermap>-1 && layermap<map_count)
3631 {
3632 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3633
3634 auto data = TheMaps[layerscreen].data[c];
3635 auto cs = TheMaps[layerscreen].cset[c];
3636 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3637 }
3638 }
3639 }
3640
3641 for(int32_t k=2; k<4; k++)
3642 {
3643 if(LayerMaskInt[k+1]!=0)
3644 {
3645 layermap=layer->layermap[k]-1;
3646
3647 if(layermap>-1 && layermap<map_count)
3648 {
3649 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3650 auto data = TheMaps[layerscreen].data[c];
3651 auto cs = TheMaps[layerscreen].cset[c];
3652 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3653 }
3654 }
3655 }
3656
3657 //Overhead L0
3658 if(LayerMaskInt[0]!=0)
3659 {
3660 auto data = TheMaps[layerscreen].data[c];
3661 if(combo_class_buf[combobuf[data].type].overhead)
3662 {
3663 auto cs = TheMaps[layerscreen].cset[c];
3664 drawcombo(dest,x,y,data,cs,0,0);
3665 }
3666 }
3667 //Overhead L1/2
3668 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3669 {
3670 for(int32_t k = 0; k < 2; ++k)
3671 {
3672 if(LayerMaskInt[k+1]!=0)
3673 {
3674 layermap=layer->layermap[k]-1;
3675
3676 if(layermap>-1 && layermap<map_count)
3677 {
3678 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3679 auto data = TheMaps[layerscreen].data[c];
3680 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3681 auto cs = TheMaps[layerscreen].cset[c];
3682 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3683 }
3684 }
3685 }
3686 }
3687
3688
3689 for(int32_t k=4; k<6; k++)
3690 {
3691 if(LayerMaskInt[k+1]!=0)
3692 {
3693 layermap=layer->layermap[k]-1;
3694
3695 if(layermap>-1 && layermap<map_count)
3696 {
3697 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3698 auto data = TheMaps[layerscreen].data[c];
3699 auto cs = TheMaps[layerscreen].cset[c];
3700 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3701 }
3702 }
3703 }
3704
3705 if(flags&cWALK)
3706 {
3707 if(LayerMaskInt[0]!=0)
3708 {
3709 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3710 }
3711
3712 for(int32_t k=0; k<2; k++)
3713 {
3714 if(LayerMaskInt[k+1]!=0)
3715 {
3716 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3717 }
3718 }
3719 }
3720
3721 if(flags&(cFLAGS|cCSET|cCTYPE))
3722 {
3723 if(LayerMaskInt[CurrentLayer]!=0)
3724 {
3725 int32_t i = c;
3726 //for(int32_t i=c; i==c; i++)
3727 {
3728 if(CurrentLayer==0)
3729 {
3730 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3731 }
3732 else
3733 {
3734 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3735
3736 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3737 {
3738 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3739 TheMaps[_lscr].data[i],
3740 TheMaps[_lscr].cset[i], flags|dark,
3741 TheMaps[_lscr].sflag[i]);
3742 }
3743 }
3744 }
3745 }
3746 }
3747
3748 if(ShowMisalignments)
3749 {
3750 switch(c)
3751 {
3752 case 0:
3753 check_alignments(dest,x,y,scr);
3754 break;
3755
3756 case 15:
3757 check_alignments(dest,x-240,y,scr);
3758 break;
3759
3760 case 160:
3761 check_alignments(dest,x,y-160,scr);
3762 break;
3763
3764 case 175:
3765 check_alignments(dest,x-240,y-160,scr);
3766 break;
3767 }
3768 }
3769 }
3770
3771 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3772 {
3773 if (InvalidBG == 2)
3774 {
3775 draw_checkerboard(dest, x, y, 16);
3776 }
3777 else if(InvalidBG == 1)
3778 {
3779 draw_static(dest, x, y, 16, 16);
3780 }
3781 else
3782 {
3783 rectfill(dest, x, y, x+15, y+15, vc(0));
3784 rect(dest, x, y, x+15, y+15, vc(15));
3785 line(dest, x, y, x+15, y+15, vc(15));
3786 line(dest, x, y+15, x+15, y, vc(15));
3787 }
3788 }
3789
3790 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3791 {
3792 if (InvalidBG == 2)
3793 {
3794 for(int32_t q = 0; q < 11; ++q)
3795 draw_checkerboard(dest, x, y + q * 16, 16);
3796 }
3797 else if(InvalidBG == 1)
3798 {
3799 draw_static(dest, x, y, 16, 176);
3800 }
3801 else
3802 {
3803 rectfill(dest, x, y, x+15, y+175, vc(0));
3804 rect(dest, x, y, x+15, y+175, vc(15));
3805 line(dest, x, y, x+15, y+175, vc(15));
3806 line(dest, x, y+175, x+15, y, vc(15));
3807 }
3808 }
3809
3810 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3811 {
3812 if (InvalidBG == 2)
3813 {
3814 for (int32_t q = 0; q < 16; ++q)
3815 draw_checkerboard(dest, x + q * 16, y, 16);
3816 }
3817 else if(InvalidBG == 1)
3818 {
3819 draw_static(dest, x, y, 256, 16);
3820 }
3821 else
3822 {
3823 rectfill(dest, x, y, x+255, y+15, vc(0));
3824 rect(dest, x, y, x+255, y+15, vc(15));
3825 line(dest, x, y, x+255, y+15, vc(15));
3826 line(dest, x, y+15, x+255, y, vc(15));
3827 }
3828 }
3829
3830 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3831 {
3832 for(int32_t i=0; i<176; i++)
3833 {
3834 word cmbdat = screens[TEMPLATE].data[i];
3835 byte cmbcset = screens[TEMPLATE].cset[i];
3836 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3837 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3838 }
3839 }
3840
3841 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3842 {
3843 for(int32_t i=0; i<176; i++)
3844 {
3845 word cmbdat = screens[TEMPLATE2].data[i];
3846 byte cmbcset = screens[TEMPLATE2].cset[i];
3847 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3848 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3849 }
3850 }
3851
3852 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3853 {
3854 word cmbdat = screens[TEMPLATE].data[pos];
3855 byte cmbcset = screens[TEMPLATE].cset[pos];
3856 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3857 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3858 }
3859
3860 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3861 {
3862 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3863 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3864 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3865 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3866 }
3867
3868 void zmap::scroll(int32_t dir, bool warp)
3869 {
3870 if(cursor.map<map_count)
3871 {
3872 switch(dir)
3873 {
3874 case up:
3875 if(warp && Map.CurrScr()->flags2&wfUP)
3876 {
3877 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3878 }
3879 else if(cursor.screen>15)
3880 {
3881 setCurrScr(cursor.screen - 16);
3882 }
3883
3884 break;
3885
3886 case down:
3887 if(warp && Map.CurrScr()->flags2&wfDOWN)
3888 {
3889 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3890 }
3891 else if(cursor.screen<MAPSCRS-16)
3892 {
3893 setCurrScr(cursor.screen + 16);
3894 }
3895
3896 break;
3897
3898 case left:
3899 if(warp && Map.CurrScr()->flags2&wfLEFT)
3900 {
3901 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3902 }
3903 else if(cursor.screen&15)
3904 {
3905 setCurrScr(cursor.screen - 1);
3906 }
3907
3908 break;
3909
3910 case right:
3911 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3912 {
3913 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3914 }
3915 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3916 {
3917 setCurrScr(cursor.screen + 1);
3918 }
3919
3920 break;
3921 }
3922 }
3923 }
3924
3925 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3926 {
3927 switch(side)
3928 {
3929 case up:
3930 switch(door)
3931 {
3932 case dWALL:
3933 case dBOMB:
3934 case dWALK:
3935 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3936 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3937 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3938 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3939 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3940 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3941 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3942 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3943 break;
3944
3945 default:
3946 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3947 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3948 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3949 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3950 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3951 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3952 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3953 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3954 break;
3955 }
3956
3957 break;
3958
3959 case down:
3960 switch(door)
3961 {
3962 case dWALL:
3963 case dBOMB:
3964 case dWALK:
3965 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
3966 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
3967 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
3968 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
3969 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
3970 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
3971 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
3972 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
3973 break;
3974
3975 default:
3976 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
3977 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
3978 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
3979 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
3980 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
3981 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
3982 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
3983 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
3984 break;
3985 }
3986
3987 break;
3988
3989 case left:
3990 switch(door)
3991 {
3992 case dWALL:
3993 case dBOMB:
3994 case dWALK:
3995 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
3996 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
3997 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
3998 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
3999 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4000 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4001 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4002 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4003 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4004 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4005 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4006 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4007 break;
4008
4009 default:
4010 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4011 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4012 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4013 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4014 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4015 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4016 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4017 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4018 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4019 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4020 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4021 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4022 break;
4023 }
4024
4025 break;
4026
4027 case right:
4028 switch(door)
4029 {
4030 case dWALL:
4031 case dBOMB:
4032 case dWALK:
4033 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4034 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4035 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4036 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4037 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4038 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4039 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4040 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4041 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4042 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4043 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4044 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4045 break;
4046
4047 default:
4048 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4049 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4050 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4051 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4052 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4053 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4054 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4055 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4056 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4057 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4058 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4059 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4060 break;
4061 }
4062
4063 break;
4064 }
4065 }
4066 void zmap::DoPutDoorCommand(int side, int door, bool force)
4067 {
4068 if(!force && screens[cursor.screen].door[side] == door)
4069 return;
4070 bool already_list = InListCommand();
4071 if(!already_list)
4072 StartListCommand();
4073 DoSetDoorCommand(cursor.screen,side,door);
4074 if(door != dNONE)
4075 {
4076 word data[176] = {0};
4077 byte cset[176] = {0};
4078 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4079 for(int q = 0; q < 176; ++q)
4080 if(data[q])
4081 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4082 }
4083 if(!already_list)
4084 FinishListCommand();
4085 }
4086 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4087 {
4088 if(screens[screen].door[side] == door)
4089 return;
4090
4091 screens[screen].door[side] = door;
4092 if(door != dNONE)
4093 {
4094 word data[176] = {0};
4095 byte cset[176] = {0};
4096 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4097 for(int q = 0; q < 176; ++q)
4098 if(data[q])
4099 {
4100 screens[screen].data[q] = data[q];
4101 screens[screen].cset[q] = cset[q];
4102 }
4103 }
4104 }
4105
4106 void list_command::execute()
4107 {
4108 for (auto command : commands)
4109 {
4110 command->execute();
4111 }
4112 }
4113
4114 void list_command::undo()
4115 {
4116 for (int i = commands.size() - 1; i >= 0; i--)
4117 {
4118 commands[i]->undo();
4119 }
4120 }
4121
4122 int list_command::size()
4123 {
4124 int s = 0;
4125 for (auto command : commands)
4126 {
4127 s += command->size();
4128 }
4129 return s;
4130 }
4131
4132 void set_combo_command::execute()
4133 {
4134 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4135 if (!scr_ptr) return;
4136
4137 if (combo != -1) scr_ptr->data[pos] = combo;
4138 scr_ptr->cset[pos] = cset;
4139 }
4140
4141 void set_combo_command::undo()
4142 {
4143 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4144 if(!mapscr_ptr) return;
4145 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4146 mapscr_ptr->cset[pos] = prev_cset;
4147 }
4148
4149 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4150 {
4151 std::array<int, 8> initd_arr;
4152 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4153
4154 return {
4155 .x = ffc.x,
4156 .y = ffc.y,
4157 .vx = ffc.vx,
4158 .vy = ffc.vy,
4159 .ax = ffc.ax,
4160 .ay = ffc.ay,
4161 .data = ffc.data,
4162 .cset = ffc.cset,
4163 .delay = ffc.delay,
4164 .link = ffc.link,
4165 .script = ffc.script,
4166 .tw = ffc.txsz,
4167 .th = ffc.tysz,
4168 .ew = ffc.hit_width,
4169 .eh = ffc.hit_height,
4170 .flags = ffc.flags,
4171 .initd = initd_arr,
4172 .layer = ffc.layer
4173 };
4174 }
4175
4176 void set_ffc_command::execute()
4177 {
4178 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4179 if(!mapscr_ptr) return;
4180
4181 mapscr_ptr->valid |= mVALID;
4182 mapscr_ptr->ffcs[i].x = data.x;
4183 mapscr_ptr->ffcs[i].y = data.y;
4184 mapscr_ptr->ffcs[i].vx = data.vx;
4185 mapscr_ptr->ffcs[i].vy = data.vy;
4186 mapscr_ptr->ffcs[i].ax = data.ax;
4187 mapscr_ptr->ffcs[i].ay = data.ay;
4188 mapscr_ptr->ffcs[i].data = data.data;
4189 mapscr_ptr->ffcs[i].cset = data.cset;
4190 mapscr_ptr->ffcs[i].delay = data.delay;
4191 mapscr_ptr->ffcs[i].link = data.link;
4192 mapscr_ptr->ffcs[i].script = data.script;
4193 mapscr_ptr->ffcs[i].flags = data.flags;
4194 mapscr_ptr->ffEffectWidth(i, data.ew);
4195 mapscr_ptr->ffEffectHeight(i, data.eh);
4196 mapscr_ptr->ffTileWidth(i, data.tw);
4197 mapscr_ptr->ffTileHeight(i, data.th);
4198 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4199 mapscr_ptr->ffcs[i].layer = data.layer;
4200 mapscr_ptr->ffcCountMarkDirty();
4201 mapscr_ptr->ffcs[i].updateSolid();
4202 }
4203
4204 void set_ffc_command::undo()
4205 {
4206 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4207 if(!mapscr_ptr) return;
4208
4209 mapscr_ptr->ffcs[i].x = prev_data.x;
4210 mapscr_ptr->ffcs[i].y = prev_data.y;
4211 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4212 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4213 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4214 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4215 mapscr_ptr->ffcs[i].data = prev_data.data;
4216 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4217 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4218 mapscr_ptr->ffcs[i].link = prev_data.link;
4219 mapscr_ptr->ffcs[i].script = prev_data.script;
4220 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4221 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4222 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4223 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4224 mapscr_ptr->ffTileHeight(i, prev_data.th);
4225 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4226 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4227 mapscr_ptr->ffcCountMarkDirty();
4228 mapscr_ptr->ffcs[i].updateSolid();
4229 }
4230
4231 void set_flag_command::execute()
4232 {
4233 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4234 if(!mapscr_ptr) return;
4235
4236 mapscr_ptr->valid |= mVALID;
4237 mapscr_ptr->sflag[pos] = flag;
4238 }
4239
4240 void set_flag_command::undo()
4241 {
4242 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4243 if(!mapscr_ptr) return;
4244 mapscr_ptr->sflag[pos] = prev_flag;
4245 }
4246
4247 void set_door_command::execute()
4248 {
4249 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4250 if(!mapscr_ptr) return;
4251
4252 mapscr_ptr->valid |= mVALID;
4253 mapscr_ptr->door[side] = door;
4254 }
4255
4256 void set_door_command::undo()
4257 {
4258 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4259 }
4260
4261 void set_dcs_command::execute()
4262 {
4263 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4264 if(!mapscr_ptr) return;
4265
4266 mapscr_ptr->valid |= mVALID;
4267 mapscr_ptr->door_combo_set = dcs;
4268 }
4269
4270 void set_dcs_command::undo()
4271 {
4272 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4273 }
4274
4275 void paste_screen_command::execute()
4276 {
4277 perform(screen.get());
4278 }
4279
4280 void paste_screen_command::undo()
4281 {
4282 if (prev_screens.size() > 1)
4283 {
4284 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4285 ASSERT(prev_screens.size() == 128);
4286 for (int i = 0; i < 128; i++)
4287 {
4288 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4289 // TODO: why not just this?
4290 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4291 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4292 }
4293 return;
4294 }
4295
4296 perform(prev_screens[0].get());
4297 }
4298
4299 int paste_screen_command::size()
4300 {
4301 return prev_screens.size() + 1;
4302 }
4303
4304 void paste_screen_command::perform(mapscr* to)
4305 {
4306 if (to)
4307 {
4308 switch (type) {
4309 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4310 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4311 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4312 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4313 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4314 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4315 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4316 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4317 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4318 case ScreenPartial: Map.Paste(*to, screen_index); break;
4319 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4320 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4321 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4322 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4323 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4324 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4325 }
4326 }
4327 else
4328 {
4329 Map.clearscr(screen_index);
4330 }
4331 refresh(rALL);
4332 }
4333
4334 void set_screen_command::execute()
4335 {
4336 if (screen)
4337 {
4338 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4339 }
4340 else
4341 {
4342 Map.clearscr(screen_index);
4343 }
4344 refresh(rALL);
4345 }
4346
4347 void set_screen_command::undo()
4348 {
4349 if (prev_screen)
4350 {
4351 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4352 }
4353 else
4354 {
4355 Map.clearscr(screen_index);
4356 }
4357 refresh(rALL);
4358 }
4359
4360 int set_screen_command::size()
4361 {
4362 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4363 }
4364
4365 static std::shared_ptr<list_command> current_list_command;
4366 void zmap::StartListCommand()
4367 {
4368 ASSERT(!current_list_command);
4369 current_list_command.reset(new list_command);
4370 }
4371
4372 void zmap::FinishListCommand()
4373 {
4374 if (current_list_command->commands.size() == 1)
4375 {
4376 input_undo_stack.push_back(current_list_command->commands[0]);
4377 }
4378 else if (current_list_command->commands.size() > 1)
4379 {
4380 input_undo_stack.push_back(current_list_command);
4381 }
4382 CapCommandHistory();
4383 current_list_command = nullptr;
4384 }
4385
4386 void zmap::RevokeListCommand()
4387 {
4388 current_list_command->undo();
4389 current_list_command = nullptr;
4390 }
4391
4392 bool zmap::InListCommand() const
4393 {
4394 return current_list_command ? true : false;
4395 }
4396
4397 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4398 {
4399 input_redo_stack = {};
4400
4401 if (!skip_execute) command->execute();
4402 if (current_list_command)
4403 {
4404 current_list_command->commands.push_back(command);
4405 if (current_list_command->commands.size() == 1)
4406 {
4407 current_list_command->cursor = command->cursor;
4408 }
4409 }
4410 else
4411 {
4412 input_undo_stack.push_back(command);
4413 CapCommandHistory();
4414 }
4415 mark_save_dirty();
4416 }
4417
4418 void zmap::UndoCommand()
4419 {
4420 if (input_undo_stack.size() <= 0) return;
4421
4422 // If not currently looking at the associated screen, first change the view
4423 // and wait for the next call to actually undo this command.
4424 auto command = input_undo_stack.back();
4425 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4426 {
4427 setCursor(command.get()->cursor);
4428 return;
4429 }
4430
4431 command->undo();
4432 input_redo_stack.push(command);
4433 input_undo_stack.pop_back();
4434 mark_save_dirty();
4435 }
4436
4437 void zmap::RedoCommand()
4438 {
4439 if (input_redo_stack.size() <= 0) return;
4440
4441 // If not currently selected the associated screen, first change the cursor
4442 // and wait for the next call to actually execute this command.
4443 auto command = input_redo_stack.top();
4444 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4445 {
4446 setCursor(command.get()->cursor);
4447 return;
4448 }
4449
4450 command->execute();
4451 input_undo_stack.push_back(command);
4452 input_redo_stack.pop();
4453 mark_save_dirty();
4454 }
4455
4456 11 void zmap::ClearCommandHistory()
4457 {
4458 11 current_list_command = nullptr;
4459 11 input_undo_stack = {};
4460 11 input_redo_stack = {};
4461 11 }
4462
4463 // Extra amount is from mapscr's vectors.
4464 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4465 // Allow the undo system to use roughly 100 MB of memory.
4466 // This doesn't count the memory used by commands that don't store a mapscr,
4467 // but that should be negligible.
4468 12 static int max_command_size = 100e6 / size_of_mapscr;
4469 void zmap::CapCommandHistory()
4470 {
4471 int size;
4472 do
4473 {
4474 size = 0;
4475 for (auto command : input_undo_stack)
4476 {
4477 size += command->size();
4478 }
4479 if (size > max_command_size) input_undo_stack.pop_front();
4480 } while (size > max_command_size);
4481 }
4482
4483 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4484 {
4485 if (!pos.is_valid(cursor))
4486 return;
4487
4488 int map = cursor.map;
4489 int screen = cursor.viewscr + pos.screen_offset();
4490 if (!AbsoluteScr(map, screen))
4491 return;
4492
4493 if (CurrentLayer)
4494 {
4495 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4496 map = scr->layermap[CurrentLayer-1]-1;
4497 screen = scr->layerscreen[CurrentLayer-1];
4498 }
4499 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4500 }
4501
4502 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4503 {
4504 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4505 if (!mapscr_ptr) return;
4506
4507 std::shared_ptr<set_combo_command> command(new set_combo_command);
4508 command->cursor = cursor;
4509 command->map = map;
4510 command->scr = scr;
4511 command->pos = pos;
4512 command->combo = combo;
4513 command->cset = cset;
4514 command->prev_combo = mapscr_ptr->data[pos];
4515 command->prev_cset = mapscr_ptr->cset[pos];
4516 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4517 {
4518 // nothing to do...
4519 return;
4520 }
4521
4522 ExecuteCommand(command);
4523 }
4524
4525 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4526 {
4527 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4528 if(!mapscr_ptr) return;
4529
4530 mapscr_ptr->ensureFFC(i);
4531
4532 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4533
4534 std::array<int, 8> initd_arr;
4535 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4536
4537 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4538
4539 command->cursor = cursor;
4540 command->map = map;
4541 command->scr = scr;
4542 command->i = i;
4543 command->data = data;
4544 command->prev_data = prev_data;
4545 if (data == prev_data)
4546 {
4547 // nothing to do...
4548 return;
4549 }
4550
4551 ExecuteCommand(command);
4552 }
4553
4554 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4555 {
4556 if (!pos.is_valid(cursor))
4557 return;
4558
4559 int map = cursor.map;
4560 int screen = cursor.viewscr + pos.screen_offset();
4561 if (!AbsoluteScr(map, screen))
4562 return;
4563
4564 if (CurrentLayer)
4565 {
4566 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4567 map = scr->layermap[CurrentLayer-1]-1;
4568 screen = scr->layerscreen[CurrentLayer-1];
4569 }
4570 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4571 }
4572
4573 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4574 {
4575 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4576 if(!mapscr_ptr) return;
4577
4578 std::shared_ptr<set_flag_command> command(new set_flag_command);
4579 command->cursor = cursor;
4580 command->map = map;
4581 command->scr = scr;
4582 command->pos = pos;
4583 command->flag = flag;
4584 command->prev_flag = mapscr_ptr->sflag[pos];
4585 if (command->flag == command->prev_flag)
4586 {
4587 // nothing to do...
4588 return;
4589 }
4590
4591 ExecuteCommand(command);
4592 }
4593
4594 void zmap::DoSetDoorCommand(int scr, int side, int door)
4595 {
4596 if(screens[scr].door[side] == door)
4597 return;
4598 std::shared_ptr<set_door_command> command(new set_door_command);
4599 command->cursor = cursor;
4600 command->side = side;
4601 command->door = door;
4602 command->prev_door = screens[scr].door[side];
4603
4604 ExecuteCommand(command);
4605 }
4606 void zmap::DoSetDCSCommand(int dcs)
4607 {
4608 if(screens[cursor.screen].door_combo_set == dcs)
4609 return;
4610 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4611 command->cursor = cursor;
4612 command->dcs = dcs;
4613 command->prev_dcs = screens[cursor.screen].door_combo_set;
4614
4615 ExecuteCommand(command);
4616 }
4617
4618 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4619 {
4620 if (screen == -1)
4621 screen = cursor.screen;
4622
4623 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4624 command->cursor = cursor;
4625 command->type = type;
4626 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4627 command->screen_index = screen;
4628
4629 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4630 {
4631 for (int i=0; i < 128; i++)
4632 {
4633 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4634 }
4635 }
4636 else
4637 {
4638 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4639 }
4640
4641 ExecuteCommand(command);
4642 }
4643
4644 void zmap::DoClearScreenCommand(int screen)
4645 {
4646 std::shared_ptr<set_screen_command> command(new set_screen_command);
4647 command->cursor = cursor;
4648 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4649 command->screen = std::shared_ptr<mapscr>(nullptr);
4650 command->screen_index = screen;
4651
4652 ExecuteCommand(command);
4653 }
4654
4655 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4656 {
4657 std::shared_ptr<set_screen_command> command(new set_screen_command);
4658 command->cursor = cursor;
4659 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4660 Template(floorcombo, floorcset, screen);
4661 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4662
4663 ExecuteCommand(command, true);
4664 }
4665
4666 void zmap::Copy(int scr)
4667 {
4668 if(screens[scr].valid&mVALID)
4669 {
4670 copy_mapscr(&copymapscr, &screens[scr]);
4671 //copymapscr=screens[scr];
4672 can_paste=true;
4673 copymap=cursor.map;
4674 copyscr=scr;
4675 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4676 copyffc = -1;
4677 }
4678 }
4679
4680 void zmap::CopyFFC(int32_t screen, int32_t n)
4681 {
4682 if(screens[screen].valid&mVALID)
4683 {
4684 copy_mapscr(&copymapscr, &screens[screen]);
4685 // Can't paste the screen itself
4686 can_paste = false;
4687 copymap=cursor.map;
4688 copyscr=screen;
4689 copyffc = n;
4690 }
4691 }
4692
4693 void zmap::Paste(const mapscr& copymapscr, int screen)
4694 {
4695 if(can_paste)
4696 {
4697 if(!(screens[screen].valid&mVALID))
4698 {
4699 screens[screen].valid |= mVALID;
4700 screens[screen].color = copymapscr.color;
4701 }
4702
4703 screens[screen].door_combo_set = copymapscr.door_combo_set;
4704
4705 for(int32_t i=0; i<4; i++)
4706 {
4707 screens[screen].door[i]=copymapscr.door[i];
4708 }
4709
4710 for(int32_t i=0; i<176; i++)
4711 {
4712 screens[screen].data[i] = copymapscr.data[i];
4713 screens[screen].cset[i] = copymapscr.cset[i];
4714 screens[screen].sflag[i] = copymapscr.sflag[i];
4715 }
4716
4717 refresh_color();
4718
4719 mark_save_dirty();
4720 }
4721 }
4722
4723 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4724 {
4725 if(can_paste)
4726 {
4727 screens[screen].undercombo = copymapscr.undercombo;
4728 screens[screen].undercset = copymapscr.undercset;
4729 mark_save_dirty();
4730 }
4731 }
4732
4733 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4734 {
4735 if(can_paste)
4736 {
4737 for(int32_t i=0; i<128; i++)
4738 {
4739 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4740 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4741 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4742 }
4743
4744 mark_save_dirty();
4745 }
4746 }
4747
4748 // TODO const mapscr& copymapscr
4749 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4750 {
4751 if(can_paste)
4752 {
4753 screens[screen].ffcs = copymapscr.ffcs;
4754 screens[screen].ffcCountMarkDirty();
4755 mark_save_dirty();
4756 }
4757 }
4758
4759 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4760 {
4761 if(can_paste)
4762 {
4763 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4764
4765 for(int32_t i=0; i<4; i++)
4766 {
4767 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4768 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4769 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4770 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4771 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4772 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4773 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4774 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4775 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4776 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4777 }
4778
4779 mark_save_dirty();
4780 }
4781 }
4782
4783 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4784 {
4785 if(can_paste)
4786 {
4787 screens[screen].csensitive = copymapscr.csensitive;
4788 screens[screen].oceansfx = copymapscr.oceansfx;
4789 screens[screen].bosssfx = copymapscr.bosssfx;
4790 screens[screen].secretsfx = copymapscr.secretsfx;
4791 screens[screen].holdupsfx = copymapscr.holdupsfx;
4792 screens[screen].flags = copymapscr.flags;
4793 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4794 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4795 screens[screen].flags3 = copymapscr.flags3;
4796 screens[screen].flags4 = copymapscr.flags4;
4797 screens[screen].flags5 = copymapscr.flags5;
4798 screens[screen].flags6 = copymapscr.flags6;
4799 screens[screen].flags7 = copymapscr.flags7;
4800 screens[screen].flags8 = copymapscr.flags8;
4801 screens[screen].flags9 = copymapscr.flags9;
4802 screens[screen].flags10 = copymapscr.flags10;
4803 screens[screen].flags11 = copymapscr.flags11;
4804 screens[screen].item = copymapscr.item;
4805 screens[screen].hasitem = copymapscr.hasitem;
4806 screens[screen].itemx = copymapscr.itemx;
4807 screens[screen].itemy = copymapscr.itemy;
4808 screens[screen].nextmap = copymapscr.nextmap;
4809 screens[screen].nextscr = copymapscr.nextscr;
4810 screens[screen].nocarry = copymapscr.nocarry;
4811 screens[screen].noreset = copymapscr.noreset;
4812 screens[screen].exstate_reset = copymapscr.exstate_reset;
4813 screens[screen].exstate_carry = copymapscr.exstate_carry;
4814 screens[screen].path[0] = copymapscr.path[0];
4815 screens[screen].path[1] = copymapscr.path[1];
4816 screens[screen].path[2] = copymapscr.path[2];
4817 screens[screen].path[3] = copymapscr.path[3];
4818 screens[screen].pattern = copymapscr.pattern;
4819 screens[screen].exitdir = copymapscr.exitdir;
4820 screens[screen].music = copymapscr.music;
4821 screens[screen].stairx = copymapscr.stairx;
4822 screens[screen].stairy = copymapscr.stairy;
4823 screens[screen].timedwarptics = copymapscr.timedwarptics;
4824 mark_save_dirty();
4825 }
4826 }
4827
4828 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4829 {
4830 if(can_paste)
4831 {
4832 screens[screen].warpreturnc = copymapscr.warpreturnc;
4833 screens[screen].warparrivalx = copymapscr.warparrivalx;
4834 screens[screen].warparrivaly = copymapscr.warparrivaly;
4835
4836 for(int32_t i=0; i<4; i++)
4837 {
4838 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4839 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4840 }
4841
4842 mark_save_dirty();
4843 }
4844 }
4845
4846 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4847 {
4848 if(can_paste)
4849 {
4850 for(int32_t i=0; i<4; i++)
4851 screens[screen].door[i] = copymapscr.door[i];
4852
4853 screens[screen].door_combo_set = copymapscr.door_combo_set;
4854 mark_save_dirty();
4855 }
4856 }
4857
4858 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4859 {
4860 if(can_paste)
4861 {
4862 for(int32_t i=0; i<6; i++)
4863 {
4864 screens[screen].layermap[i] = copymapscr.layermap[i];
4865 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4866 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4867 }
4868
4869 mark_save_dirty();
4870 }
4871 }
4872
4873 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4874 {
4875 if(can_paste)
4876 {
4877 screens[screen].room = copymapscr.room;
4878 screens[screen].catchall = copymapscr.catchall;
4879 mark_save_dirty();
4880 }
4881 }
4882
4883 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4884 {
4885 if(can_paste)
4886 {
4887 screens[screen].guy = copymapscr.guy;
4888 screens[screen].guytile = copymapscr.guytile;
4889 screens[screen].guycs = copymapscr.guycs;
4890 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4891 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4892 screens[screen].str = copymapscr.str;
4893 mark_save_dirty();
4894 }
4895 }
4896
4897 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4898 {
4899 if(can_paste)
4900 {
4901 screens[screen].color = copymapscr.color;
4902 screens[screen].valid|=mVALID;
4903 refresh_color();
4904
4905 mark_save_dirty();
4906 }
4907 }
4908
4909 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4910 {
4911 if(can_paste)
4912 {
4913 copy_mapscr(&screens[screen], &copymapscr);
4914 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4915 screens[screen].valid|=mVALID;
4916
4917 refresh_color();
4918
4919 mark_save_dirty();
4920 }
4921 }
4922
4923
4924 void zmap::PasteToAll(const mapscr& copymapscr)
4925 {
4926 if(can_paste)
4927 {
4928 for(int32_t x=0; x<128; x++)
4929 {
4930 if(!(screens[x].valid&mVALID))
4931 {
4932 screens[x].valid |= mVALID;
4933 screens[x].color = copymapscr.color;
4934 }
4935
4936 for(int32_t i=0; i<176; i++)
4937 {
4938 screens[x].data[i] = copymapscr.data[i];
4939 screens[x].cset[i] = copymapscr.cset[i];
4940 screens[x].sflag[i] = copymapscr.sflag[i];
4941 }
4942 }
4943
4944 refresh_color();
4945
4946 mark_save_dirty();
4947 }
4948 }
4949
4950 void zmap::PasteAllToAll(const mapscr& copymapscr)
4951 {
4952 if(can_paste)
4953 {
4954 for(int32_t x=0; x<128; x++)
4955 {
4956 copy_mapscr(&screens[x], &copymapscr);
4957 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
4958 //screens[x]=copymapscr;
4959 }
4960
4961 refresh_color();
4962
4963 mark_save_dirty();
4964 }
4965 }
4966
4967 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
4968 {
4969 if(can_paste)
4970 {
4971 for(int32_t i=0; i<10; i++)
4972 screens[screen].enemy[i]=copymapscr.enemy[i];
4973 }
4974 }
4975
4976 bool zmap::CanGoBack() const
4977 {
4978 return !cursor_undo_stack.empty();
4979 }
4980
4981 bool zmap::CanGoForward() const
4982 {
4983 return !cursor_redo_stack.empty();
4984 }
4985
4986 void zmap::GoBack()
4987 {
4988 if (!CanGoBack())
4989 return;
4990
4991 cursor_redo_stack.push(cursor);
4992
4993 ConfigureCursorHistory(false);
4994 setCursor(cursor_undo_stack.back());
4995 ConfigureCursorHistory(true);
4996
4997 cursor_undo_stack.pop_back();
4998 }
4999
5000 void zmap::GoForward()
5001 {
5002 if (!CanGoForward())
5003 return;
5004
5005 cursor_undo_stack.push_back(cursor);
5006
5007 ConfigureCursorHistory(false);
5008 setCursor(cursor_redo_stack.top());
5009 ConfigureCursorHistory(true);
5010
5011 cursor_redo_stack.pop();
5012 }
5013
5014 void zmap::CapCursorHistory()
5015 {
5016 int max_history_size = 1000;
5017 while (cursor_undo_stack.size() > max_history_size)
5018 cursor_undo_stack.pop_front();
5019 }
5020
5021 void zmap::ConfigureCursorHistory(bool enable)
5022 {
5023 cursor_history_enabled = enable;
5024 }
5025
5026 void zmap::setCopyFFC(int32_t n)
5027 {
5028 copyffc = n;
5029 }
5030
5031 void zmap::update_combo_cycling()
5032 {
5033 if(!prv_mode||!prv_cmbcycle)
5034 {
5035 return;
5036 }
5037
5038 int32_t x;
5039 int32_t newdata[176];
5040 int32_t newcset[176];
5041 bool restartanim[MAXCOMBOS] = {0};
5042
5043 for(int32_t i=0; i<176; i++)
5044 {
5045 newdata[i]=-1;
5046 newcset[i]=-1;
5047
5048 x=prvscr.data[i];
5049
5050 //time to restart
5051 if((combobuf[x].aclk>=combobuf[x].speed) &&
5052 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5053 combobuf[x].can_cycle())
5054 {
5055 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5056 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5057
5058 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5059 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5060 int32_t c = newdata[i];
5061
5062 if(combobuf[c].animflags & AF_CYCLE)
5063 {
5064 restartanim[c]=true;
5065 }
5066 }
5067 }
5068
5069 for(int32_t i=0; i<176; i++)
5070 {
5071 x=prvscr.data[i];
5072
5073 //time to restart
5074 if((combobuf[x].aclk>=combobuf[x].speed) &&
5075 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5076 combobuf[x].can_cycle())
5077 {
5078 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5079 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5080
5081 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5082 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5083 int32_t c = newdata[i];
5084
5085 if(combobuf[c].animflags & AF_CYCLE)
5086 {
5087 restartanim[c]=true;
5088 }
5089 }
5090 }
5091
5092 for(int32_t i=0; i<176; i++)
5093 {
5094 if(newdata[i]==-1)
5095 continue;
5096
5097 prvscr.data[i]=newdata[i];
5098 prvscr.cset[i]=newcset[i];
5099 }
5100
5101 word maxffc = prvscr.numFFC();
5102 for(word i=0; i<maxffc; i++)
5103 {
5104 ffcdata& ffc = prvscr.ffcs[i];
5105 newcombo const& cmb = combobuf[ffc.data];
5106
5107 //time to restart
5108 if((cmb.aclk>=cmb.speed) &&
5109 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5110 cmb.can_cycle())
5111 {
5112 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5113 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5114
5115 if(!(cmb.animflags & AF_CYCLENOCSET))
5116 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5117
5118 if(combobuf[ffc.data].animflags & AF_CYCLE)
5119 {
5120 restartanim[ffc.data]=true;
5121 }
5122 prvscr.ffcs[i].data = ffc.data;
5123 prvscr.ffcs[i].cset=ffc.cset;
5124 }
5125 }
5126
5127
5128 if(get_qr(qr_CMBCYCLELAYERS))
5129 {
5130 for(int32_t j=0; j<6; j++)
5131 {
5132 if(!prvlayers[j].valid)
5133 continue;
5134
5135 for(int32_t i=0; i<176; i++)
5136 {
5137 newdata[i]=-1;
5138 newcset[i]=-1;
5139
5140 x=(prvlayers[j]).data[i];
5141
5142 //time to restart
5143 if((combobuf[x].aclk>=combobuf[x].speed) &&
5144 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5145 combobuf[x].can_cycle())
5146 {
5147 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5148 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5149
5150 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5151 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5152 int32_t c = newdata[i];
5153
5154 if(combobuf[c].animflags & AF_CYCLE)
5155 {
5156 restartanim[c]=true;
5157 }
5158 }
5159 }
5160
5161 for(int32_t i=0; i<176; i++)
5162 {
5163 x=(prvlayers[j]).data[i];
5164
5165 //time to restart
5166 if((combobuf[x].aclk>=combobuf[x].speed) &&
5167 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5168 combobuf[x].can_cycle())
5169 {
5170 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5171 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5172
5173 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5174 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5175 int32_t c = newdata[i];
5176
5177 if(combobuf[c].animflags & AF_CYCLE)
5178 {
5179 restartanim[c]=true;
5180 }
5181 }
5182 }
5183
5184 for(int32_t i=0; i<176; i++)
5185 {
5186 if(newdata[i]==-1)
5187 continue;
5188
5189 prvlayers[j].data[i]=newdata[i];
5190 prvlayers[j].cset[i]=newcset[i];
5191 }
5192 }
5193 }
5194
5195 for(int32_t i=0; i<MAXCOMBOS; i++)
5196 {
5197 if(restartanim[i])
5198 {
5199 combobuf[i].tile = combobuf[i].o_tile;
5200 combobuf[i].cur_frame=0;
5201 combobuf[i].aclk = 0;
5202 }
5203 }
5204 }
5205
5206 void zmap::update_freeform_combos()
5207 {
5208 if(!prv_mode||!prv_cmbcycle)
5209 {
5210 return;
5211 }
5212
5213 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5214 word maxffc = prvscr.numFFC();
5215 for(int32_t i=0; i<maxffc; i++)
5216 {
5217 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5218 {
5219 for(int32_t j=0; j<maxffc; j++)
5220 {
5221 if(i!=j)
5222 {
5223 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5224 {
5225 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5226 {
5227 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5228 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5229 {
5230 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5231 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5232 if(prvscr.ffcs[j].flags&ffc_changethis)
5233 {
5234 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5235 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5236 }
5237
5238 if(prvscr.ffcs[j].flags&ffc_changenext)
5239 prvscr.ffcs[i].data += 1;
5240
5241 if(prvscr.ffcs[j].flags&ffc_changeprev)
5242 prvscr.ffcs[i].data -= 1;
5243
5244 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5245 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5246 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5247
5248 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5249 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5250 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5251 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5252
5253 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5254 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5255 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5256 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5257 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5258
5259 if(prvscr.ffcs[i].flags&ffc_carryover)
5260 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5261 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5262
5263 prvscr.ffcs[i].flags&=~ffc_changer;
5264 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5265 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5266
5267 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5268 {
5269 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5270 }
5271
5272 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5273 {
5274 int32_t k=0;
5275
5276 if(prvscr.ffcs[j].flags&ffc_swapnext)
5277 k=j<(MAXFFCS-1)?j+1:0;
5278
5279 if(prvscr.ffcs[j].flags&ffc_swapprev)
5280 k=j>0?j-1:(MAXFFCS-1);
5281
5282 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5283 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5284 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5285 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5286 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5287 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5288 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5289 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5290 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5291 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5292 }
5293 }
5294 }
5295 }
5296 }
5297 }
5298
5299 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5300 {
5301 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5302 {
5303 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5304 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5305 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5306 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5307 }
5308 else
5309 {
5310 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5311 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5312 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5313 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5314 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5315 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5316
5317 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5318 {
5319 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5320
5321 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5322
5323 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5324
5325 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5326 }
5327 }
5328 }
5329 else
5330 {
5331 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5332 prvscr.ffcs[i].delay--;
5333 }
5334
5335 if(prvscr.ffcs[i].x<-32)
5336 {
5337 if(prvscr.flags6&fWRAPAROUNDFF)
5338 {
5339 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5340 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5341 }
5342 else
5343 {
5344 prvscr.ffcs[i].data = 0;
5345 prvscr.ffcs[i].flags&=~ffc_carryover;
5346 }
5347 }
5348
5349 if(prvscr.ffcs[i].y<-32)
5350 {
5351 if(prvscr.flags6&fWRAPAROUNDFF)
5352 {
5353 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5354 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5355 }
5356 else
5357 {
5358 prvscr.ffcs[i].data = 0;
5359 prvscr.ffcs[i].flags&=~ffc_carryover;
5360 }
5361 }
5362
5363 if(prvscr.ffcs[i].x>=288)
5364 {
5365 if(prvscr.flags6&fWRAPAROUNDFF)
5366 {
5367 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5368 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5369 }
5370 else
5371 {
5372 prvscr.ffcs[i].data = 0;
5373 prvscr.ffcs[i].flags&=~ffc_carryover;
5374 }
5375 }
5376
5377 if(prvscr.ffcs[i].y>=208)
5378 {
5379 if(prvscr.flags6&fWRAPAROUNDFF)
5380 {
5381 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5382 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5383 }
5384 else
5385 {
5386 prvscr.ffcs[i].data = 0;
5387 prvscr.ffcs[i].flags&=~ffc_carryover;
5388 }
5389 }
5390
5391 }
5392 }
5393 }
5394
5395 void zmap::goto_dmapscr(int dmap, int scr)
5396 {
5397 goto_mapscr(DMaps[dmap].map, scr + DMaps[dmap].xoff);
5398 }
5399 void zmap::goto_mapscr(int map, int scr)
5400 {
5401 auto new_cursor = cursor;
5402 new_cursor.map = map;
5403 new_cursor.setScreen(scr);
5404 setCursor(std::move(new_cursor));
5405 }
5406
5407 void zmap::dowarp(int32_t type, int32_t index)
5408 {
5409 set_warpback();
5410 if(type==0)
5411 {
5412
5413 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5414 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5415
5416 switch(screens[cursor.screen].tilewarptype[index])
5417 {
5418 case wtCAVE:
5419 case wtNOWARP:
5420 break;
5421
5422 default:
5423 goto_dmapscr(dmap, scr);
5424 break;
5425 }
5426 }
5427 else if(type==1)
5428 {
5429 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5430 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5431
5432 switch(screens[cursor.screen].sidewarptype[index])
5433 {
5434 case wtCAVE:
5435 case wtNOWARP:
5436 break;
5437
5438 default:
5439 goto_dmapscr(dmap, scr);
5440 break;
5441 }
5442 }
5443 }
5444
5445 extern int32_t prv_twon;
5446
5447 void zmap::prv_dowarp(int32_t type, int32_t index)
5448 {
5449 if(type==0)
5450 {
5451
5452 int32_t dmap=prvscr.tilewarpdmap[index];
5453 int32_t scr=prvscr.tilewarpscr[index];
5454
5455 switch(prvscr.tilewarptype[index])
5456 {
5457 case wtCAVE:
5458 case wtNOWARP:
5459 break;
5460
5461 default:
5462 //setCurrMap(DMaps[dmap].map);
5463 //setCurrScr(scr+DMaps[dmap].xoff);
5464 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5465 refresh_color();
5466 //prv_cmbcycle=0;
5467 break;
5468 }
5469 }
5470 else if(type==1)
5471 {
5472 int32_t dmap=prvscr.sidewarpdmap[index];
5473 int32_t scr=prvscr.sidewarpscr[index];
5474
5475 switch(prvscr.sidewarptype[index])
5476 {
5477 case wtCAVE:
5478 case wtNOWARP:
5479 break;
5480
5481 default:
5482 //setCurrMap(DMaps[dmap].map);
5483 //setCurrScr(scr+DMaps[dmap].xoff);
5484 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5485 refresh_color();
5486 //prv_cmbcycle=0;
5487 break;
5488 }
5489 }
5490
5491 if(prv_twon)
5492 {
5493 prv_time=get_prvscr()->timedwarptics;
5494 }
5495 }
5496
5497 void zmap::dowarp2(int32_t ring,int32_t index)
5498 {
5499 set_warpback();
5500 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5501 }
5502
5503 void zmap::set_warpback()
5504 {
5505 warpbackmap = cursor.map;
5506 warpbackscreen = cursor.screen;
5507 }
5508 bool zmap::has_warpback()
5509 {
5510 return warpbackmap && warpbackscreen
5511 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5512 }
5513 void zmap::warpback()
5514 {
5515 if(!has_warpback())
5516 return;
5517
5518 int m = cursor.map, s = cursor.screen;
5519 goto_mapscr(*warpbackmap, *warpbackscreen);
5520 warpbackmap = m;
5521 warpbackscreen = s;
5522 }
5523
5524 bool save_msgstrs(const char *path)
5525 {
5526 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5527
5528 if(!f)
5529 {
5530 return false;
5531 }
5532
5533 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5534 {
5535 pack_fclose(f);
5536 return true;
5537 }
5538
5539 pack_fclose(f);
5540 return false;
5541 }
5542
5543 1 bool save_strings_tsv(const char *path)
5544 {
5545 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5546
5547
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5548 {
5549 return false;
5550 }
5551
5552
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5553 {
5554 1 pack_fclose(f);
5555 1 return true;
5556 }
5557
5558 pack_fclose(f);
5559 return false;
5560 1 }
5561
5562 bool save_msgstrs_text(const char *path)
5563 {
5564 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5565
5566 if(!f)
5567 {
5568 return false;
5569 }
5570
5571 if(writestrings_text(f)==0)
5572 {
5573 pack_fclose(f);
5574 return true;
5575 }
5576
5577 pack_fclose(f);
5578 return false;
5579 }
5580
5581 bool load_msgstrs(const char *path, int32_t startstring)
5582 {
5583 //these are here to bypass compiler warnings about unused arguments
5584 startstring=startstring;
5585
5586 dword section_id;
5587 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5588
5589 if(!f)
5590 {
5591 return false;
5592 }
5593
5594 if(!p_mgetl(&section_id,f))
5595 {
5596 return false;
5597 }
5598
5599 if(section_id==ID_STRINGS)
5600 {
5601 if(readstrings(f, &header)==0)
5602 {
5603 pack_fclose(f);
5604 return true;
5605 }
5606 else
5607 {
5608 pack_fclose(f);
5609 return false;
5610 }
5611 }
5612
5613 pack_fclose(f);
5614 return false;
5615 }
5616
5617 bool load_strings_tsv(const char *path)
5618 {
5619 try
5620 {
5621 parse_strings_tsv(util::read_text_file(path));
5622 }
5623 catch (std::exception& ex)
5624 {
5625 InfoDialog("Import .tsv Error", ex.what()).show();
5626 return false;
5627 }
5628 return true;
5629 }
5630
5631 bool save_pals(const char *path)
5632 {
5633 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5634
5635 if(!f)
5636 {
5637 return false;
5638 }
5639
5640 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5641 {
5642 pack_fclose(f);
5643 return true;
5644 }
5645
5646 pack_fclose(f);
5647 return false;
5648 }
5649
5650 bool load_pals(const char *path, int32_t startcset)
5651 {
5652 dword section_id;
5653 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5654
5655 if(!f)
5656 {
5657 return false;
5658 }
5659
5660 if(!p_mgetl(&section_id,f))
5661 {
5662 return false;
5663 }
5664
5665 if(section_id==ID_CSETS)
5666 {
5667 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5668 {
5669 pack_fclose(f);
5670 loadlvlpal(Color);
5671 return true;
5672 }
5673 else
5674 {
5675 pack_fclose(f);
5676 return false;
5677 }
5678 }
5679
5680 return false;
5681 }
5682
5683 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5684 bool save_guys(const char *path)
5685 {
5686 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5687
5688 if(!f)
5689 {
5690 return false;
5691 }
5692
5693 /*
5694 int32_t id = ID_GUYS;
5695 if(!p_mputl(id,f))
5696 {
5697 return false;
5698 }
5699 */
5700
5701 zquestheader h;
5702 h.zelda_version = 0x250;
5703 h.build = 21;
5704
5705 if(writeguys(f, &h)==0)
5706 {
5707 pack_fclose(f);
5708 return true;
5709 }
5710
5711 pack_fclose(f);
5712 return false;
5713 }
5714
5715 bool load_guys(const char *path)
5716 {
5717 dword section_id;
5718 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5719
5720 if(!f)
5721 {
5722 return false;
5723 }
5724
5725 if(!p_mgetl(&section_id,f))
5726 {
5727 pack_fclose(f);
5728 return false;
5729 }
5730
5731 zquestheader h;
5732 h.zelda_version = 0x250;
5733 h.build = 21;
5734
5735 if(section_id==ID_GUYS)
5736 {
5737 if(readguys(f, &h)==0)
5738 {
5739 pack_fclose(f);
5740 return true;
5741 }
5742 }
5743
5744 pack_fclose(f);
5745 return false;
5746 }
5747
5748
5749 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5750 bool save_combo_alias(const char *path)
5751 {
5752 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5753
5754 if(!f)
5755 {
5756 return false;
5757 }
5758
5759 zquestheader h;
5760 h.zelda_version = 0x250;
5761 h.build = 21;
5762
5763 if(writecomboaliases(f, 0, 0)==0)
5764 {
5765 pack_fclose(f);
5766 return true;
5767 }
5768
5769 pack_fclose(f);
5770 return false;
5771 }
5772
5773 bool load_combo_alias(const char *path)
5774 {
5775 dword section_id;
5776 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5777
5778 if(!f)
5779 {
5780 return false;
5781 }
5782
5783 if(!p_mgetl(&section_id,f))
5784 {
5785 pack_fclose(f);
5786 return false;
5787 }
5788
5789 zquestheader h;
5790 h.zelda_version = 0x250;
5791 h.build = 21;
5792
5793 if(section_id==ID_COMBOALIASES)
5794 {
5795 if(readcomboaliases(f, &h, 0, 0)==0)
5796 {
5797 pack_fclose(f);
5798 return true;
5799 }
5800 }
5801
5802 pack_fclose(f);
5803 return false;
5804 }
5805
5806 bool load_zgp(const char *path)
5807 {
5808 dword section_id;
5809 word section_version;
5810 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5811
5812 if(!f)
5813 return false;
5814
5815 if(!p_mgetl(&section_id,f))
5816 {
5817 pack_fclose(f);
5818 return false;
5819 }
5820
5821 if(section_id!=ID_GRAPHICSPACK)
5822 {
5823 pack_fclose(f);
5824 return false;
5825 }
5826
5827 //section version info
5828 if(!p_igetw(&section_version,f))
5829 {
5830 return 2;
5831 }
5832
5833 if(!read_deprecated_section_cversion(f))
5834 {
5835 return 3;
5836 }
5837
5838 //tiles
5839 if(!p_mgetl(&section_id,f))
5840 {
5841 pack_fclose(f);
5842 return false;
5843 }
5844
5845 if(section_id==ID_TILES)
5846 {
5847 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5848 {
5849 pack_fclose(f);
5850 init_tiles(true, &header);
5851 return false;
5852 }
5853 }
5854 else
5855 {
5856 pack_fclose(f);
5857 return false;
5858 }
5859
5860 //combos
5861 if(!p_mgetl(&section_id,f))
5862 {
5863 pack_fclose(f);
5864 return false;
5865 }
5866
5867 if(section_id==ID_COMBOS)
5868 {
5869 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5870 {
5871 pack_fclose(f);
5872 return false;
5873 }
5874 }
5875 else
5876 {
5877 pack_fclose(f);
5878 return false;
5879 }
5880
5881 //palettes
5882 if(!p_mgetl(&section_id,f))
5883 {
5884 pack_fclose(f);
5885 return false;
5886 }
5887
5888 if(section_id==ID_CSETS)
5889 {
5890 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5891 {
5892 pack_fclose(f);
5893 return false;
5894 }
5895 }
5896 else
5897 {
5898 pack_fclose(f);
5899 return false;
5900 }
5901
5902 //items
5903 if(!p_mgetl(&section_id,f))
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908
5909 if(section_id==ID_ITEMS)
5910 {
5911 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5912 {
5913 pack_fclose(f);
5914 return false;
5915 }
5916 }
5917 else
5918 {
5919 pack_fclose(f);
5920 return false;
5921 }
5922
5923 //weapons
5924 if(!p_mgetl(&section_id,f))
5925 {
5926 pack_fclose(f);
5927 return false;
5928 }
5929
5930 if(section_id==ID_WEAPONS)
5931 {
5932 if(readweapons(f, &header)!=0)
5933 {
5934 pack_fclose(f);
5935 return false;
5936 }
5937 }
5938 else
5939 {
5940 pack_fclose(f);
5941 return false;
5942 }
5943
5944 //read the triforce pieces info and make sure it worked
5945 //really do this?
5946
5947 //read the game icons info and make sure it worked
5948 if(!p_mgetl(&section_id,f))
5949 {
5950 pack_fclose(f);
5951 return false;
5952 }
5953
5954 if(section_id==ID_ICONS)
5955 {
5956 if(readgameicons(f, &header, &QMisc)!=0)
5957 {
5958 pack_fclose(f);
5959 return false;
5960 }
5961 }
5962 else
5963 {
5964 pack_fclose(f);
5965 return false;
5966 }
5967
5968 //read the misc colors info and map styles info and make sure it worked
5969 if(!p_mgetl(&section_id,f))
5970 {
5971 pack_fclose(f);
5972 return false;
5973 }
5974
5975 if(section_id==ID_COLORS)
5976 {
5977 if(readmisccolors(f, &header, &QMisc)!=0)
5978 {
5979 pack_fclose(f);
5980 return false;
5981 }
5982 }
5983 else
5984 {
5985 pack_fclose(f);
5986 return false;
5987 }
5988
5989 //read the door combo sets and make sure it worked
5990 if(!p_mgetl(&section_id,f))
5991 {
5992 pack_fclose(f);
5993 return false;
5994 }
5995
5996 if(section_id==ID_DOORS)
5997 {
5998 if(readdoorcombosets(f, &header)!=0)
5999 {
6000 pack_fclose(f);
6001 return false;
6002 }
6003 }
6004 else
6005 {
6006 pack_fclose(f);
6007 return false;
6008 }
6009
6010 //read the template screens and make sure it worked
6011 //really do this?
6012
6013 //yay! it worked! close the file and say everything was ok.
6014 loadlvlpal(Color);
6015 setup_combo_animations();
6016 setup_combo_animations2();
6017 pack_fclose(f);
6018 return true;
6019 }
6020
6021 bool save_zgp(const char *path)
6022 {
6023 reset_combo_animations();
6024 reset_combo_animations2();
6025
6026 //open the file
6027 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6028
6029 if(!f)
6030 return false;
6031
6032 dword section_id=ID_GRAPHICSPACK;
6033 dword section_version=V_GRAPHICSPACK;
6034
6035 //section id
6036 if(!p_mputl(section_id,f))
6037 {
6038 return 1;
6039 }
6040
6041 //section version info
6042 if(!p_iputw(section_version,f))
6043 {
6044 return 2;
6045 }
6046
6047 if(!write_deprecated_section_cversion(section_version,f))
6048 {
6049 return 3;
6050 }
6051
6052 //tiles
6053 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6054 {
6055 pack_fclose(f);
6056 return false;
6057 }
6058
6059 //combos
6060 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6061 {
6062 pack_fclose(f);
6063 return false;
6064 }
6065
6066 //palettes
6067 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6068 {
6069 pack_fclose(f);
6070 return false;
6071 }
6072
6073 //items
6074 if(writeitems(f, &header)!=0)
6075 {
6076 pack_fclose(f);
6077 return false;
6078 }
6079
6080 //weapons
6081 if(writeweapons(f, &header)!=0)
6082 {
6083 pack_fclose(f);
6084 return false;
6085 }
6086
6087 //write the triforce pieces info and make sure it worked
6088 //really do this?
6089
6090 //write the game icons info and make sure it worked
6091 if(writegameicons(f, &header)!=0)
6092 {
6093 pack_fclose(f);
6094 return false;
6095 }
6096
6097 //write the misc colors info and map styles info and make sure it worked
6098 if(writemisccolors(f, &header)!=0)
6099 {
6100 pack_fclose(f);
6101 return false;
6102 }
6103
6104 //write the door combo sets and make sure it worked
6105 if(writedoorcombosets(f, &header)!=0)
6106 {
6107 pack_fclose(f);
6108 return false;
6109 }
6110
6111 //write the template screens and make sure it worked
6112 //really do this?
6113
6114 pack_fclose(f);
6115 return true;
6116 }
6117
6118 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6119 {
6120 //open the file
6121 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6122
6123 if(!f)
6124 return false;
6125
6126 dword section_id=ID_SUBSCREEN;
6127 dword s_version=V_SUBSCREEN;
6128
6129 if(!p_mputl(section_id,f))
6130 {
6131 pack_fclose(f);
6132 return false;
6133 }
6134
6135 if(!p_iputw(s_version,f))
6136 {
6137 pack_fclose(f);
6138 return false;
6139 }
6140
6141 if(!write_deprecated_section_cversion(s_version,f))
6142 {
6143 pack_fclose(f);
6144 return false;
6145 }
6146
6147 if(savefrom.write(f))
6148 {
6149 pack_fclose(f);
6150 return false;
6151 }
6152
6153 pack_fclose(f);
6154 return true;
6155 }
6156
6157 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6158 {
6159 //open the file
6160 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6161
6162 if(!f)
6163 return false;
6164
6165 dword section_id;
6166 dword s_version;
6167
6168 if(!p_mgetl(&section_id,f))
6169 {
6170 pack_fclose(f);
6171 return false;
6172 }
6173
6174 if(section_id!=ID_SUBSCREEN)
6175 {
6176 pack_fclose(f);
6177 return false;
6178 }
6179
6180 if(!p_igetw(&s_version,f))
6181 {
6182 pack_fclose(f);
6183 return false;
6184 }
6185
6186 if (s_version > V_SUBSCREEN)
6187 return qe_version;
6188
6189 if(!read_deprecated_section_cversion(f))
6190 {
6191 pack_fclose(f);
6192 return false;
6193 }
6194
6195 if(s_version < 8)
6196 {
6197 subscreen_group g;
6198 memset(&g,0,sizeof(subscreen_group));
6199 if(read_one_old_subscreen(f,&g,s_version)!=0)
6200 {
6201 pack_fclose(f);
6202 return false;
6203 }
6204 if(g.ss_type != loadto.sub_type)
6205 {
6206 pack_fclose(f);
6207 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6208 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6209 return false;
6210 }
6211 loadto.clear();
6212 if(g.objects[0].type != ssoNULL)
6213 loadto.load_old(g);
6214 }
6215 else
6216 {
6217 ZCSubscreen tmp = ZCSubscreen();
6218 if (tmp.read(f, s_version))
6219 {
6220 pack_fclose(f);
6221 return false;
6222 }
6223 if(tmp.sub_type != loadto.sub_type)
6224 {
6225 pack_fclose(f);
6226 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6227 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6228 return false;
6229 }
6230 loadto.clear();
6231 loadto = tmp;
6232 }
6233
6234 pack_fclose(f);
6235 return true;
6236 }
6237
6238 bool setMapCount2(int32_t c)
6239 {
6240 int32_t oldmapcount=map_count;
6241 int32_t cur_map=Map.getCurrMap();
6242
6243 bound(c,1,MAXMAPS);
6244 map_count=c;
6245
6246 try
6247 {
6248 TheMaps.resize(c*MAPSCRS);
6249 Map.force_refr_pointer();
6250 map_infos.resize(c);
6251 }
6252 catch(...)
6253 {
6254 displayinfo("Error","Failed to change map count.");
6255 return false;
6256 }
6257
6258 bound(cur_map,0,c-1);
6259 if(map_count>oldmapcount)
6260 {
6261 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6262 {
6263 // copy the default palette to the new maps
6264 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6265
6266 Map.setCurrMap(mc);
6267 for(int32_t ms=0; ms<MAPSCRS; ms++)
6268 Map.clearscr(ms);
6269 }
6270 Map.setCurrMap(cur_map);
6271 }
6272 else
6273 {
6274 Map.setCurrMap(cur_map);
6275 if(!layers_valid(Map.CurrScr()))
6276 fix_layers(Map.CurrScr(), false);
6277
6278 for(int32_t i=0; i<MAXDMAPS; i++)
6279 {
6280 if(DMaps[i].map>=map_count)
6281 {
6282 DMaps[i].map=map_count-1;
6283 }
6284 }
6285 }
6286
6287 return true;
6288 }
6289
6290 extern BITMAP *bmap;
6291
6292 static bool loading_file_new = false;
6293 int32_t init_quest(std::string tileset_path)
6294 {
6295 if (tileset_path.empty())
6296 tileset_path = DEFAULT_TILESET;
6297
6298 loading_file_new = true;
6299 load_quest(tileset_path.c_str());
6300 loading_file_new = false;
6301
6302 set_window_title("ZC Editor - Untitled Quest");
6303 zinit.last_map = 0;
6304 zinit.last_screen = 0;
6305
6306 if(bmap != NULL)
6307 {
6308 destroy_bitmap(bmap);
6309 bmap=NULL;
6310 }
6311
6312 return 0;
6313 }
6314
6315 void set_questpwd(std::string_view pwd, bool use_keyfile)
6316 {
6317 header.use_keyfile=use_keyfile;
6318
6319 // string_view actually has some quirks that make it less than ideal here.
6320 // It'd probably be best to replace it, but this works for now.
6321 memset(header.password, 0, 256);
6322 strcpy(header.password, pwd.data());
6323 header.dirty_password=true;
6324
6325 cvs_MD5Context ctx;
6326 cvs_MD5Init(&ctx);
6327 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6328 cvs_MD5Final(header.pwd_hash, &ctx);
6329 }
6330
6331
6332 bool is_null_pwd_hash(uint8_t *pwd_hash)
6333 {
6334 cvs_MD5Context ctx;
6335 uint8_t md5sum[16];
6336 char pwd[2]="";
6337
6338 cvs_MD5Init(&ctx);
6339 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6340 cvs_MD5Final(md5sum, &ctx);
6341
6342 return (memcmp(md5sum,pwd_hash,16)==0);
6343 }
6344
6345 static DIALOG pwd_dlg[] =
6346 {
6347 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6348 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6349 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6350 // 2 (filename)
6351 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6352 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6353 // 4 (challenge hash)
6354 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6355 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6356 // 6 (password)
6357 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6358 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6359 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6360 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6361 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6362 };
6363
6364 int32_t reverse_string(char* str)
6365 {
6366
6367 if(NULL==str)
6368 {
6369 return -1; //no string
6370 }
6371
6372 int32_t l=(int32_t)strlen(str)-1; //get the string length
6373
6374 if(1==l)
6375 {
6376 return 1;
6377 }
6378
6379 char c;
6380
6381 for(int32_t x=0; x < l; x++,l--)
6382 {
6383 c = str[x];
6384 str[x] = str[l];
6385 str[l] = c;
6386 }
6387
6388 return 0;
6389 }
6390
6391 #ifdef __GNUC__
6392 #pragma GCC diagnostic push
6393 #pragma GCC diagnostic ignored "-Wunreachable-code"
6394 #endif
6395
6396 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6397 {
6398
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6399 11 return 1;
6400
6401 #ifdef __EMSCRIPTEN__
6402 return 1;
6403 #endif
6404
6405 //Protection against compiling a release version with password protection off.
6406 static bool passguard = false;
6407
6408 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6409 #define MUST_HAVE_PASSWORD
6410 passguard = true;
6411 #endif
6412
6413 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6414 #if (defined _MSC_VER || defined _NPASS)
6415 return 1;
6416 #endif
6417 #endif
6418 if(devpwd()) return 1;
6419
6420 char hash_string[33];
6421
6422 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6423 {
6424 return 1;
6425 }
6426
6427 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6428 return true;
6429
6430 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6431 pwd_dlg[2].dp=get_filename(filename);
6432 cvs_MD5Context ctx;
6433 uint8_t md5sum[16]={0};
6434 char response[33]="";
6435 char prompt[256]="";
6436
6437 memcpy(md5sum, hdr->pwd_hash, 16);
6438
6439 for(int32_t i=0; i<300; ++i)
6440 {
6441 for(int32_t j=0; j<16; ++j)
6442 {
6443 sprintf(response+j*2, "%02x", md5sum[j]);
6444 }
6445
6446 if(i&1)
6447 {
6448 reverse_string(response);
6449 }
6450
6451 if(i==149)
6452 {
6453 strcpy(hash_string, response);
6454 }
6455
6456 cvs_MD5Init(&ctx);
6457 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6458 cvs_MD5Final(md5sum, &ctx);
6459 }
6460
6461 pwd_dlg[4].dp=hash_string;
6462
6463 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6464 {
6465 sprintf(prompt,"%s",response);
6466 }
6467
6468 pwd_dlg[6].dp=prompt;
6469
6470 large_dialog(pwd_dlg);
6471
6472 int32_t cancel = do_zqdialog(pwd_dlg,6);
6473
6474 if(cancel == 8)
6475 return 2;
6476
6477 bool ret=check_questpwd(hdr, prompt);
6478
6479 if(!ret)
6480 {
6481 ret=(strcmp(response,prompt)==0);
6482 }
6483 return ret ? 1 : 0;
6484 11 }
6485
6486 void set_rules(byte* newrules);
6487 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6488 {
6489 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6490
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6491 {
6492
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
22 auto [ret, dsa] = alert_confirm_dsa("Apply New Bugfixes",
6493
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6494 "\nWould you like to apply them?"
6495 "\n(Applies 'Bugfix' rule template, un-checking compat rules)");
6496
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(ret)
6497 {
6498 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6499 }
6500
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(dsa)
6501 {
6502 zc_set_config("zquest",cfg,1);
6503 }
6504 11 }
6505 11 }
6506
6507 #ifdef __GNUC__
6508 #pragma GCC diagnostic pop
6509 #endif
6510
6511 11 int32_t load_quest(const char *filename, bool show_progress)
6512 {
6513 11 zq_freeze_all_rti();
6514
6515 char buf[2048];
6516 byte skip_flags[4];
6517
6518 11 dword tileset_flags = 0;
6519
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6520 {
6521 44 skip_flags[i]=0;
6522 44 }
6523
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6524 7634 set_qr(i,0);
6525 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6526
6527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6528 {
6529 init_quest(DEFAULT_TILESET);
6530 }
6531 else
6532 {
6533 11 int32_t accessret = quest_access(filename, &header);
6534
6535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6536 {
6537 init_quest(DEFAULT_TILESET);
6538
6539 if(accessret == 0)
6540 ret=qe_pwd;
6541 else
6542 ret=qe_cancel;
6543 }
6544 else
6545 {
6546 11 Map.clear();
6547
6548
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6549
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 int view_size = zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1);
6550
6551
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 Map.setCursor(MapCursor{
6552
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 .map = vbound(zinit.last_map, 0, map_count - 1),
6553 11 .screen = zinit.last_screen,
6554 11 .viewscr = zinit.last_screen,
6555 11 .size = view_size,
6556 });
6557
6558 extern int32_t current_mappage;
6559 11 current_mappage = 0;
6560 11 bool found_default = false;
6561
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6562 {
6563 83 auto &pg = map_page[q];
6564
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6565 {
6566 2 current_mappage = q;
6567 2 break;
6568 }
6569
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6570 72 continue;
6571 else
6572 {
6573 9 current_mappage = q;
6574 9 found_default = true;
6575 }
6576 9 }
6577
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6578
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6579
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6580 11 saved = true;
6581
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6582
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6583
6584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6585 {
6586 destroy_bitmap(bmap);
6587 bmap=NULL;
6588 }
6589
6590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6591 {
6592 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6593 set_window_title(buf);
6594 }
6595 11 }
6596 }
6597
6598 11 Map.ClearCommandHistory();
6599
6600
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6601 {
6602 void load_size_poses();
6603 load_size_poses();
6604 }
6605
6606 11 return ret;
6607 }
6608
6609 int32_t load_tileset(const char *filename, dword tsetflags)
6610 {
6611 zq_freeze_all_rti();
6612
6613 byte skip_flags[4];
6614
6615 for(int32_t i=0; i<4; ++i)
6616 skip_flags[i]=0;
6617 for(int32_t i=0; i<qr_MAX; i++)
6618 set_qr(i,0);
6619 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6620
6621 if(ret!=qe_OK)
6622 init_quest(DEFAULT_TILESET);
6623 else
6624 {
6625 if(tsetflags & TILESET_BUGFIX)
6626 applyRuleTemplate(ruletemplateFixCompat);
6627 if(tsetflags & TILESET_SCR_BUGFIX)
6628 applyRuleTemplate(ruletemplateFixZSCompat);
6629
6630 int32_t accessret = quest_access(filename, &header);
6631
6632 if(accessret != 1)
6633 {
6634 init_quest(DEFAULT_TILESET);
6635
6636 if(accessret == 0)
6637 ret=qe_pwd;
6638 else
6639 ret=qe_cancel;
6640 }
6641 else
6642 {
6643 Map.clear();
6644 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6645 Map.setCurrScr(zinit.last_screen);
6646 extern int32_t current_mappage;
6647 current_mappage = 0;
6648 bool found_default = false;
6649 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6650 {
6651 auto &pg = map_page[q];
6652 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6653 {
6654 current_mappage = q;
6655 break;
6656 }
6657 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6658 continue;
6659 else
6660 {
6661 current_mappage = q;
6662 found_default = true;
6663 }
6664 }
6665 refresh(rALL);
6666 refresh_pal();
6667 set_rules(quest_rules);
6668
6669 if(bmap != NULL)
6670 {
6671 destroy_bitmap(bmap);
6672 bmap=NULL;
6673 }
6674
6675 set_window_title("ZC Editor - Untitled Quest");
6676 first_save = false;
6677 mark_save_dirty();
6678 memset(filepath,0,255);
6679 memset(temppath,0,255);
6680 }
6681 }
6682
6683 Map.ClearCommandHistory();
6684
6685 return ret;
6686 }
6687
6688 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6689 {
6690
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6691 new_return(1);
6692
6693
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6694 new_return(2);
6695
6696
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6697 new_return(3);
6698
6699
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6700 new_return(4);
6701
6702
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6703 {
6704
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6705 new_return(5);
6706
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6707 new_return(6);
6708 1363650 }
6709
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6710 new_return(7);
6711
6712
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6713 new_return(8);
6714
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6715 new_return(9);
6716
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6717 new_return(10);
6718
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6719 new_return(11);
6720
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6721 new_return(12);
6722
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6723 new_return(13);
6724
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6725 new_return(14);
6726
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6727 new_return(15);
6728
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6729 new_return(16);
6730
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6731 new_return(17);
6732
6733
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6734 new_return(18);
6735
6736
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6737 new_return(19);
6738
6739
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6740 new_return(20);
6741
6742
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6743 new_return(21);
6744
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6745 new_return(22);
6746
6747
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6748 new_return(23);
6749
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6750 new_return(24);
6751
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6752 new_return(25);
6753
6754
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6755 new_return(26);
6756
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6757
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6758 new_return(27);
6759
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6760 new_return(28);
6761 272730 return 0;
6762 }
6763
6764 130 bool write_midi(MIDI *m,PACKFILE *f)
6765 {
6766 int32_t c;
6767
6768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6769
6770
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6771 {
6772
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6773
6774
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6775 {
6776
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6777 return false;
6778 1264 }
6779 4160 }
6780
6781 130 return true;
6782 130 }
6783
6784 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6785 {
6786 9 dword section_id=ID_HEADER;
6787 9 dword section_version=V_HEADER;
6788 9 dword section_size=0;
6789
6790 //file header string
6791
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6792 {
6793 new_return(1);
6794 }
6795
6796 //section id
6797
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6798 {
6799 new_return(2);
6800 }
6801
6802 //section version info
6803
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6804 {
6805 new_return(3);
6806 }
6807
6808
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
6809 {
6810 new_return(4);
6811 }
6812
6813
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6814 {
6815 18 fake_pack_writing=(writecycle==0);
6816
6817 //section size
6818
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6819 {
6820 new_return(5);
6821 }
6822
6823 18 writesize=0;
6824
6825 //finally... section data
6826
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6827 {
6828 new_return(6);
6829 }
6830
6831
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6832 {
6833 new_return(7);
6834 }
6835
6836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6837 {
6838 new_return(8);
6839 }
6840
6841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(Header->internal,f))
6842 {
6843 new_return(10);
6844 }
6845
6846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(Header->quest_number,f))
6847 {
6848 new_return(11);
6849 }
6850
6851
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->version,16,f))
6852 {
6853 new_return(12);
6854 }
6855
6856
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->minver,16,f))
6857 {
6858 new_return(13);
6859 }
6860
6861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6862 {
6863 new_return(14);
6864 }
6865
6866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6867 {
6868 new_return(15);
6869 }
6870
6871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(Header->use_keyfile,f))
6872 {
6873 new_return(16);
6874 }
6875
6876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6877 {
6878 new_return(17);
6879 }
6880
6881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6882 {
6883 new_return(19);
6884 }
6885
6886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(0,f)) //why are we doing this?
6887 //this is for map count, it seems. -Z
6888 {
6889 new_return(20);
6890 }
6891
6892 18 auto version = getVersion();
6893
6894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.major,f))
6895 {
6896 new_return(21);
6897 }
6898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.minor,f))
6899 {
6900 new_return(22);
6901 }
6902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.patch,f))
6903 {
6904 new_return(23);
6905 }
6906 // Fourth component is deprecated.
6907
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6908 {
6909 new_return(24);
6910 }
6911
6912 // Numerous prerelease stages is deprecated.
6913
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6914 {
6915 new_return(25);
6916 }
6917
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6918 {
6919 new_return(26);
6920 }
6921
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6922 {
6923 new_return(27);
6924 }
6925
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6926 {
6927 new_return(28);
6928 }
6929
6930
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6931 {
6932 new_return(29);
6933 }
6934
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6935 {
6936 new_return(30);
6937 }
6938
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6939 {
6940 new_return(31);
6941 }
6942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6943 {
6944 new_return(32);
6945 }
6946
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6947 {
6948 new_return(33);
6949 }
6950
6951 // This is no longer set to anything.
6952 const char* tempsig[256];
6953 18 memset(tempsig, 0, 256);
6954
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6955 {
6956 new_return(34);
6957 }
6958
6959 char tempcompilersig[256];
6960 18 memset(tempcompilersig, 0, 256);
6961 18 strcpy(tempcompilersig, COMPILER_NAME);
6962
6963
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6964 {
6965 new_return(35);
6966 }
6967
6968 char tempcompilerversion[256];
6969 18 memset(tempcompilerversion, 0, 256);
6970 #ifdef _MSC_VER
6971 zc_itoa(_MSC_VER,tempcompilerversion,10);
6972 #else
6973 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6974 #endif
6975
6976
6977
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6978 {
6979 new_return(36);
6980 }
6981
6982
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
6983 {
6984 new_return(37);
6985 }
6986
6987 // V_ZC_COMPILERSIG - a deprecated version field.
6988
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
6989 {
6990 new_return(38);
6991 }
6992 #ifdef _MSC_VER
6993 if(!p_iputl((_MSC_VER / 100),f))
6994 {
6995 new_return(39);
6996 }
6997 #else
6998
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
6999 {
7000 new_return(39);
7001 }
7002 #endif
7003
7004
7005
7006 #ifdef _MSC_VER
7007 if(!p_iputl((_MSC_VER % 100),f))
7008 {
7009 new_return(41);
7010 }
7011 #else
7012
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7013 {
7014 new_return(41);
7015 }
7016 #endif
7017
7018 #ifdef _MSC_VER
7019 # if _MSC_VER >= 1400
7020 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7021 {
7022 new_return(40);
7023 }
7024 # else
7025 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7026 {
7027 new_return(40);
7028 }
7029 #endif
7030 #else
7031
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7032 {
7033 new_return(40);
7034 }
7035 #endif
7036
7037 #ifdef _MSC_VER
7038 if(!p_iputl((_MSC_BUILD),f))
7039 {
7040 new_return(42);
7041 }
7042 #else
7043
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7044 {
7045 new_return(42);
7046 }
7047 #endif
7048
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7049 {
7050 new_return(43);
7051 }
7052
7053 // Modules were removed (replaced by zinfo).
7054 char tempmodulename[1024];
7055 18 memset(tempmodulename, 0, 1024);
7056
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7057 {
7058 new_return(44);
7059 }
7060
7061 char tempdate[256];
7062 18 memset(tempdate, 0, 256);
7063 18 strcpy(tempdate, __DATE__);
7064
7065
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7066 {
7067 new_return(45);
7068 }
7069 char temptime[256];
7070 18 memset(temptime, 0, 256);
7071 18 strcpy(temptime, __TIME__);
7072
7073
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7074 {
7075 new_return(46);
7076 }
7077
7078
7079 char temptimezone[6];
7080 18 memset(temptimezone, 0, 6);
7081 18 strcpy(temptimezone, __TIMEZONE__);
7082
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7083 {
7084 new_return(47);
7085 }
7086
7087
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7088 {
7089 new_return(48);
7090 }
7091
7092
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7093 {
7094 new_return(49);
7095 }
7096
7097
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7098 {
7099 new_return(50);
7100 }
7101
7102
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7103 {
7104 9 section_size=writesize;
7105 9 }
7106 18 }
7107
7108
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7109 {
7110 displayinfo("Error: writeheader()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7111 }
7112
7113 9 new_return(0);
7114 }
7115
7116 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7117 {
7118 //these are here to bypass compiler warnings about unused arguments
7119 9 Header=Header;
7120
7121 9 dword section_id=ID_RULES;
7122 9 dword section_version=V_RULES;
7123 9 dword section_size=0;
7124
7125 //section id
7126
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7127 {
7128 new_return(1);
7129 }
7130
7131 //section version info
7132
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7133 {
7134 new_return(2);
7135 }
7136
7137
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7138 {
7139 new_return(3);
7140 }
7141
7142
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputl(V_COMPATRULE,f))
7143 {
7144 new_return(6);
7145 }
7146
7147
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7148 {
7149 18 fake_pack_writing=(writecycle==0);
7150
7151 //section size
7152
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7153 {
7154 new_return(4);
7155 }
7156
7157 18 writesize=0;
7158
7159 //finally... section data
7160
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7161 {
7162 new_return(5);
7163 }
7164
7165
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7166 {
7167 9 section_size=writesize;
7168 9 }
7169 18 }
7170
7171
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7172 {
7173 displayinfo("Error: writerules()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7174 }
7175
7176 9 new_return(0);
7177 }
7178
7179
7180 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7181 {
7182 //these are here to bypass compiler warnings about unused arguments
7183 9 Header=Header;
7184
7185 9 dword section_id=ID_DOORS;
7186 9 dword section_version=V_DOORS;
7187 9 dword section_size=0;
7188
7189 //section id
7190
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7191 {
7192 new_return(1);
7193 }
7194
7195 //section version info
7196
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7197 {
7198 new_return(2);
7199 }
7200
7201
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7202 {
7203 new_return(3);
7204 }
7205
7206
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7207 {
7208 18 fake_pack_writing=(writecycle==0);
7209
7210 //section size
7211
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7212 {
7213 new_return(4);
7214 }
7215
7216 18 writesize=0;
7217
7218 //finally... section data
7219
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7220 {
7221 new_return(5);
7222 }
7223
7224
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 320 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7225 {
7226 //name
7227 char name[21];
7228 320 memset(name, 21, (char)0);
7229 320 strcpy(name, DoorComboSetNames[i].c_str());
7230
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7231 {
7232 new_return(6);
7233 }
7234
7235 //up door
7236
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7237 {
7238
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7239 {
7240
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7241 {
7242 new_return(7);
7243 }
7244 11520 }
7245 2880 }
7246
7247
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7248 {
7249
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7250 {
7251
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7252 {
7253 new_return(8);
7254 }
7255 11520 }
7256 2880 }
7257
7258 //down door
7259
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7260 {
7261
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7262 {
7263
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7264 {
7265 new_return(9);
7266 }
7267 11520 }
7268 2880 }
7269
7270
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7271 {
7272
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7273 {
7274
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7275 {
7276 new_return(10);
7277 }
7278 11520 }
7279 2880 }
7280
7281
7282 //left door
7283
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7284 {
7285
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7286 {
7287
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7288
7289 {
7290 new_return(11);
7291 }
7292 17280 }
7293 2880 }
7294
7295
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7296 {
7297
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7298 {
7299
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7300 {
7301 new_return(12);
7302 }
7303 17280 }
7304 2880 }
7305
7306 //right door
7307
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7308 {
7309
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7310 {
7311
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7312 {
7313 new_return(13);
7314 }
7315 17280 }
7316 2880 }
7317
7318
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7319 {
7320
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7321 {
7322
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7323 {
7324 new_return(14);
7325 }
7326 17280 }
7327 2880 }
7328
7329
7330 //up bomb rubble
7331
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7332 {
7333
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7334 {
7335 new_return(15);
7336 }
7337 640 }
7338
7339
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7340 {
7341
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7342 {
7343 new_return(16);
7344 }
7345 640 }
7346
7347 //down bomb rubble
7348
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7349 {
7350
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7351 {
7352 new_return(17);
7353 }
7354 640 }
7355
7356
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7357 {
7358
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7359 {
7360 new_return(18);
7361 }
7362 640 }
7363
7364 //left bomb rubble
7365
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7366 {
7367
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7368 {
7369 new_return(19);
7370 }
7371 960 }
7372
7373
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7374 {
7375
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7376 {
7377 new_return(20);
7378 }
7379 960 }
7380
7381 //right bomb rubble
7382
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7383 {
7384
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7385 {
7386 new_return(21);
7387 }
7388 960 }
7389
7390
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7391 {
7392
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7393 {
7394 new_return(22);
7395 }
7396 960 }
7397
7398 //walkthrough stuff
7399
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7400 {
7401
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7402 {
7403 new_return(23);
7404 }
7405 1280 }
7406
7407
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7408 {
7409
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7410 {
7411 new_return(24);
7412 }
7413 1280 }
7414
7415 //flags
7416
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 640 times.
960 for(int32_t j=0; j<2; j++)
7417 {
7418
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7419 {
7420 new_return(25);
7421 }
7422 640 }
7423 320 }
7424
7425
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7426 {
7427 9 section_size=writesize;
7428 9 }
7429 18 }
7430
7431
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7432 {
7433 displayinfo("Error: writedoorcombosets()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7434 }
7435
7436 9 new_return(0);
7437 }
7438
7439 9216 int32_t write_one_dmap(PACKFILE* f, int index)
7440 {
7441 9216 DMaps[index].validate_subscreens();
7442
7443
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].map,f))
7444 {
7445 new_return(6);
7446 }
7447
7448
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].level,f))
7449 {
7450 new_return(7);
7451 }
7452
7453
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].xoff,f))
7454 {
7455 new_return(8);
7456 }
7457
7458
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].compass,f))
7459 {
7460 new_return(9);
7461 }
7462
7463
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].color,f))
7464 {
7465 new_return(10);
7466 }
7467
7468
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].cont,f))
7469 {
7470 new_return(12);
7471 }
7472
7473
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].type,f))
7474 {
7475 new_return(13);
7476 }
7477
7478
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7479 {
7480
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[index].grid[j],f))
7481 {
7482 new_return(14);
7483 }
7484 73728 }
7485
7486
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].name,sizeof(DMaps[0].name)-1,f))
7487 {
7488 new_return(15);
7489 }
7490
7491
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[index].title,f))
7492 {
7493 new_return(16);
7494 }
7495
7496
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].intro,sizeof(DMaps[0].intro)-1,f))
7497 {
7498 new_return(17);
7499 }
7500
7501
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[0],f))
7502 {
7503 new_return(18);
7504 }
7505
7506
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[0],f))
7507 {
7508 new_return(19);
7509 }
7510
7511
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[1],f))
7512 {
7513 new_return(20);
7514 }
7515
7516
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[1],f))
7517 {
7518 new_return(21);
7519 }
7520
7521
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[0],f))
7522 {
7523 new_return(22);
7524 }
7525
7526
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[0],f))
7527 {
7528 new_return(23);
7529 }
7530
7531
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[1],f))
7532 {
7533 new_return(24);
7534 }
7535
7536
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[1],f))
7537 {
7538 new_return(25);
7539 }
7540
7541
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].active_subscreen,f))
7542 {
7543 new_return(26);
7544 }
7545
7546
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].passive_subscreen,f))
7547 {
7548 new_return(27);
7549 }
7550
7551 byte disabled[32];
7552 9216 memset(disabled,0,32);
7553
7554
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7555 {
7556
1/2
✓ Branch 0 taken 2359296 times.
✗ Branch 1 not taken.
2359296 if(DMaps[index].disableditems[j])
7557 {
7558 disabled[j/8] |= (1 << (j%8));
7559 }
7560 2359296 }
7561
7562
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7563 {
7564 new_return(28);
7565 }
7566
7567
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].flags,f))
7568 new_return(29);
7569
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].sideview,f))
7570 new_return(30);
7571
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].script,f))
7572 new_return(31);
7573
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7574
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].initD[q],f))
7575 new_return(32);
7576
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7577
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7578
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[index].initD_label[q][w],f))
7579 73728 new_return(33);
7580
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].active_sub_script,f))
7581 new_return(34);
7582
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].passive_sub_script,f))
7583 new_return(35);
7584
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7585
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].sub_initD[q],f))
7586 new_return(36);
7587
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7588
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7589
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].sub_initD_label[q][w],f))
7590 73728 new_return(37);
7591
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].onmap_script,f))
7592 new_return(38);
7593
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7594
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].onmap_initD[q],f))
7595 new_return(39);
7596
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7597
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7598
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].onmap_initD_label[q][w],f))
7599 73728 new_return(40);
7600
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].mirrorDMap,f))
7601 new_return(41);
7602
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].overlay_subscreen, f))
7603 new_return(46);
7604
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].intro_string_id, f))
7605 new_return(47);
7606
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[index].flags & dmfCUSTOM_GRAVITY)
7607 {
7608 if (!p_iputzf(DMaps[index].dmap_gravity, f))
7609 new_return(48);
7610 if (!p_iputzf(DMaps[index].dmap_terminal_v, f))
7611 new_return(49);
7612 }
7613
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].map_subscreen, f))
7614 new_return(50);
7615
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].floor, f))
7616 new_return(51);
7617
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].music, f))
7618 new_return(52);
7619 9216 return 0;
7620 }
7621 9 int32_t writedmaps(PACKFILE *f, word, word, word start_dmap, word max_dmaps)
7622 {
7623 9 word dmap_count=count_dmaps();
7624 9 dword section_id=ID_DMAPS;
7625 9 dword section_version=V_DMAPS;
7626 9 dword section_size=0;
7627
7628 //section id
7629
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7630 {
7631 new_return(1);
7632 }
7633
7634 //section version info
7635
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7636 {
7637 new_return(2);
7638 }
7639
7640
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7641 {
7642 new_return(3);
7643 }
7644
7645
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7646 {
7647 18 fake_pack_writing=(writecycle==0);
7648
7649 //section size
7650
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7651 {
7652 new_return(4);
7653 }
7654
7655 18 writesize=0;
7656
7657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7659
7660 //finally... section data
7661
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7662 {
7663 new_return(5);
7664 }
7665
7666
7667
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7668 {
7669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (auto ret = write_one_dmap(f, i))
7670 return ret;
7671 9216 }
7672
7673
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7674 {
7675 9 section_size=writesize;
7676 9 }
7677 18 }
7678
7679
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7680 {
7681 displayinfo("Error: writedmaps()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7682 }
7683
7684 9 new_return(0);
7685 9 }
7686
7687 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7688 {
7689 //these are here to bypass compiler warnings about unused arguments
7690 9 Header=Header;
7691
7692 9 dword section_id=ID_COLORS;
7693 9 dword section_version=V_COLORS;
7694 9 dword section_size = 0;
7695
7696 //section id
7697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7698 {
7699 new_return(1);
7700 }
7701
7702
7703 //section version info
7704
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7705 {
7706 new_return(2);
7707 }
7708
7709
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7710 {
7711 new_return(3);
7712 }
7713
7714
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7715 {
7716 18 fake_pack_writing=(writecycle==0);
7717
7718 //section size
7719
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7720 {
7721 new_return(4);
7722 }
7723
7724 18 writesize=0;
7725
7726
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7727 {
7728 new_return(5);
7729 }
7730
7731
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7732 {
7733 new_return(6);
7734 }
7735
7736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7737 {
7738 new_return(7);
7739 }
7740
7741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7742 {
7743 new_return(8);
7744 }
7745
7746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7747 {
7748 new_return(9);
7749 }
7750
7751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7752 {
7753 new_return(10);
7754 }
7755
7756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7757 {
7758 new_return(11);
7759 }
7760
7761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7762 {
7763 new_return(12);
7764 }
7765
7766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7767 {
7768 new_return(13);
7769 }
7770
7771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7772 {
7773 new_return(14);
7774 }
7775
7776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7777 {
7778 new_return(15);
7779 }
7780
7781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7782 {
7783 new_return(16);
7784 }
7785
7786
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7787 {
7788 new_return(17);
7789 }
7790
7791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7792 {
7793 new_return(18);
7794 }
7795
7796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7797 {
7798 new_return(19);
7799 }
7800
7801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7802 {
7803 new_return(20);
7804 }
7805
7806
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7807 {
7808 new_return(21);
7809 }
7810
7811
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7812 {
7813 new_return(22);
7814 }
7815
7816
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7817 {
7818 new_return(23);
7819 }
7820
7821
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7822 {
7823 new_return(24);
7824 }
7825
7826
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7827 {
7828 new_return(31);
7829 }
7830
7831
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7832 {
7833 new_return(32);
7834 }
7835
7836
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7837 {
7838 new_return(33);
7839 }
7840
7841
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7842 {
7843 new_return(34);
7844 }
7845
7846
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7847 {
7848 new_return(35);
7849 }
7850
7851
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7852 {
7853 new_return(36);
7854 }
7855
7856
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7857 {
7858 new_return(37);
7859 }
7860
7861
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7862 {
7863 new_return(38);
7864 }
7865
7866
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7867 {
7868 new_return(39);
7869 }
7870
7871
7872
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7873 {
7874 9 section_size=writesize;
7875 9 }
7876 18 }
7877
7878
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7879 {
7880 displayinfo("Error: writemisccolors()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7881 }
7882
7883 9 new_return(0);
7884 }
7885
7886 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7887 {
7888 //these are here to bypass compiler warnings about unused arguments
7889 9 Header=Header;
7890
7891 9 dword section_id=ID_ICONS;
7892 9 dword section_version=V_ICONS;
7893 9 dword section_size = 0;
7894
7895 //section id
7896
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7897 {
7898 new_return(1);
7899 }
7900
7901 //section version info
7902
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7903 {
7904 new_return(2);
7905 }
7906
7907
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7908 {
7909 new_return(3);
7910 }
7911
7912
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7913 {
7914 18 fake_pack_writing=(writecycle==0);
7915
7916 //section size
7917
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7918 {
7919 new_return(4);
7920 }
7921
7922 18 writesize=0;
7923
7924
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
7925 {
7926
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
7927 {
7928 new_return(5);
7929 }
7930 72 }
7931
7932
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7933 {
7934 9 section_size=writesize;
7935 9 }
7936 18 }
7937
7938
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7939 {
7940 displayinfo("Error: writegameicons()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7941 }
7942
7943 9 new_return(0);
7944 }
7945
7946 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
7947 {
7948 //these are here to bypass compiler warnings about unused arguments
7949 9 Header=Header;
7950
7951 9 dword section_id=ID_MISC;
7952 9 dword section_version=V_MISC;
7953 9 word shops=count_shops(&QMisc);
7954 9 word infos=count_infos(&QMisc);
7955 9 word warprings=count_warprings(&QMisc);
7956 9 word triforces=8;
7957 9 dword section_size = 0;
7958
7959 //section id
7960
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7961 {
7962 new_return(1);
7963 }
7964
7965
7966 //section version info
7967
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7968 {
7969 new_return(2);
7970 }
7971
7972
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7973 {
7974 new_return(3);
7975 }
7976
7977
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7978 {
7979 18 fake_pack_writing=(writecycle==0);
7980
7981 //section size
7982
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7983 {
7984 new_return(4);
7985 }
7986
7987 18 writesize=0;
7988
7989 //shops
7990
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
7991 {
7992 new_return(5);
7993 }
7994
7995
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
7996 {
7997
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
7998 {
7999 new_return(6);
8000 }
8001
8002
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8003 {
8004
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8005 {
8006 new_return(7);
8007 }
8008 480 }
8009
8010
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8011 {
8012
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8013 {
8014 new_return(8);
8015 }
8016 480 }
8017
8018
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8019 {
8020
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8021 {
8022 new_return(9);
8023 }
8024 480 }
8025 160 }
8026
8027 //infos
8028
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8029 {
8030 new_return(10);
8031 }
8032
8033
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8034 {
8035
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8036 {
8037 new_return(11);
8038 }
8039
8040
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8041 {
8042
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8043 {
8044 new_return(12);
8045 }
8046 480 }
8047
8048
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8049 {
8050
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8051 {
8052 new_return(13);
8053 }
8054 480 }
8055 160 }
8056
8057 //warp rings
8058
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8059 {
8060 new_return(14);
8061 }
8062
8063
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8064 {
8065
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8066 {
8067
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8068 {
8069 new_return(15);
8070 }
8071 1872 }
8072
8073
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8074 {
8075
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8076 {
8077 new_return(16);
8078 }
8079 1872 }
8080
8081
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8082 {
8083 new_return(17);
8084 }
8085 208 }
8086
8087 //triforce pieces
8088
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8089 {
8090
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8091 {
8092 new_return(18);
8093 }
8094 144 }
8095
8096 //end string
8097
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8098 {
8099 new_return(19);
8100 }
8101
8102 //V_MISC >= 8
8103
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8104 {
8105
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8106 {
8107
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8108 {
8109 new_return(20);
8110 }
8111 480 }
8112 160 }
8113 //V_MISC >= 9
8114
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8115 {
8116
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8117 new_return(21);
8118 576 }
8119
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8120 {
8121
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 73728 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8122
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8123 new_return(22);
8124 576 }
8125 //V_MISC >= 11
8126
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8127 new_return(23);
8128
8129 //V_MISC >= 12
8130
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8131 {
8132
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8133 new_return(24);
8134 4608 }
8135
8136 //V_MISC >= 13
8137
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8138 {
8139 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8140
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8141 new_return(25);
8142
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8143 {
8144
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8145 new_return(25);
8146
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8147 new_return(25);
8148 3456 }
8149
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8150 new_return(25);
8151
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8152 new_return(25);
8153 1152 }
8154
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8155 {
8156 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8157
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8158 new_return(26);
8159
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8160 {
8161
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8162 new_return(26);
8163
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8164 new_return(26);
8165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_putc(bst->cset[j], f))
8166 new_return(26);
8167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->price[j], f))
8168 new_return(26);
8169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8170 new_return(26);
8171 13824 }
8172 4608 }
8173
8174 //V_MISC >= 14
8175
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8176 {
8177
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8178 new_return(27);
8179 4608 }
8180
8181 //V_MISC >= 17
8182 18 byte save_menu_count = 0;
8183
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(size_t q = 0; q < NUM_SAVE_MENUS; ++q)
8184
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if (!QMisc.save_menus[q].is_empty())
8185 save_menu_count = q+1;
8186
8187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(save_menu_count, f))
8188 new_return(28);
8189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(size_t q = 0; q < save_menu_count; ++q)
8190 {
8191 SaveMenu const& menu = QMisc.save_menus[q];
8192
8193 byte empty = menu.is_empty() ? 1 : 0;
8194
8195 if (!p_putc(empty, f))
8196 new_return(29);
8197 if (empty) continue;
8198
8199 if (!p_putcstr(menu.name, f))
8200 new_return(30);
8201
8202 if (!p_iputw(menu.flags, f))
8203 new_return(31);
8204
8205 if (!p_iputl(menu.cursor_tile, f))
8206 new_return(32);
8207
8208 if (!p_putc(menu.cursor_cset, f))
8209 new_return(33);
8210
8211 if (!p_putc(menu.cursor_sfx, f))
8212 new_return(34);
8213
8214 if (!p_putc(menu.choose_sfx, f))
8215 new_return(35);
8216
8217 if (!p_putc(menu.bg_color, f))
8218 new_return(36);
8219
8220 if (!p_putc(menu.hspace, f))
8221 new_return(37);
8222
8223 if (!p_putc(menu.vspace, f))
8224 new_return(38);
8225
8226 if (!p_putc(menu.opt_x, f))
8227 new_return(39);
8228
8229 if (!p_putc(menu.opt_y, f))
8230 new_return(40);
8231
8232 if (!p_putc(menu.text_align, f))
8233 new_return(41);
8234
8235 if (!p_putc(menu.textbox_align, f))
8236 new_return(42);
8237
8238 if (!p_iputw(menu.close_frames, f))
8239 new_return(43);
8240
8241 if (!p_putc(menu.close_flash_rate, f))
8242 new_return(44);
8243
8244 if (!p_iputw(menu.music, f))
8245 new_return(45);
8246
8247 if (!p_iputl(menu.bg_tile, f))
8248 new_return(46);
8249
8250 if (!p_putc(menu.bg_cset, f))
8251 new_return(47);
8252
8253 if (!p_putc(menu.bg_tw, f))
8254 new_return(48);
8255
8256 if (!p_putc(menu.bg_th, f))
8257 new_return(49);
8258
8259 byte opt_count = zc_min(menu.options.size(), MAX_SAVEMENU_OPTIONS);
8260 if (!p_putc(opt_count, f))
8261 new_return(50);
8262
8263 for (size_t q = 0; q < opt_count; ++q)
8264 {
8265 SaveMenuOption const& opt = menu.options[q];
8266
8267 if (!p_putcstr(opt.text, f))
8268 new_return(51);
8269
8270 if (!p_iputw(opt.flags, f))
8271 new_return(52);
8272
8273 if (!p_putc(opt.color, f))
8274 new_return(53);
8275
8276 if (!p_putc(opt.picked_color, f))
8277 new_return(54);
8278
8279 if (!p_iputl(opt.font, f))
8280 new_return(55);
8281
8282 if (!p_iputw(opt.gen_script, f))
8283 new_return(56);
8284 }
8285 }
8286
8287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!p_putc(QMisc.savemenu_game_over, f))
8288 new_return(57);
8289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!p_putc(QMisc.savemenu_f6, f))
8290 new_return(58);
8291
8292
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8293 {
8294 9 section_size=writesize;
8295 9 }
8296 18 }
8297
8298
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8299 {
8300 displayinfo("Error: writemisc()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8301 }
8302
8303 9 new_return(0);
8304 }
8305
8306 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8307 {
8308 //these are here to bypass compiler warnings about unused arguments
8309 9 Header=Header;
8310
8311 9 dword section_id=ID_ITEMS;
8312 9 dword section_version=V_ITEMS;
8313 // dword section_size=0;
8314 9 dword section_size = 0;
8315
8316 //section id
8317
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8318 {
8319 new_return(1);
8320 }
8321
8322 //section version info
8323
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8324 {
8325 new_return(2);
8326 }
8327
8328
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8329 {
8330 new_return(3);
8331 }
8332
8333
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8334 {
8335 18 fake_pack_writing=(writecycle==0);
8336
8337 //section size
8338
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8339 {
8340 new_return(4);
8341 }
8342
8343 18 writesize=0;
8344
8345 //finally... section data
8346
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8347 {
8348 new_return(5);
8349 }
8350
8351
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8352 {
8353
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8354 {
8355 new_return(5);
8356 }
8357 4608 }
8358
8359
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8360 {
8361
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8362 {
8363 new_return(6);
8364 }
8365
8366
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8367 {
8368 new_return(7);
8369 }
8370
8371
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8372 {
8373 new_return(8);
8374 }
8375
8376
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8377 {
8378 new_return(9);
8379 }
8380
8381
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8382 {
8383 new_return(10);
8384 }
8385
8386
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8387 {
8388 new_return(11);
8389 }
8390
8391
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8392 {
8393 new_return(12);
8394 }
8395
8396
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8397 {
8398 new_return(13);
8399 }
8400
8401
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8402 {
8403 new_return(14);
8404 }
8405
8406
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8407 {
8408 new_return(14);
8409 }
8410
8411
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8412 {
8413 new_return(15);
8414 }
8415
8416
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8417 {
8418 new_return(16);
8419 }
8420
8421
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8422 {
8423 new_return(17);
8424 }
8425
8426
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8427 {
8428 new_return(18);
8429 }
8430
8431
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8432 {
8433 new_return(19);
8434 }
8435
8436
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8437 {
8438 new_return(21);
8439 }
8440
8441
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8442 {
8443 new_return(22);
8444 }
8445
8446
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8447 {
8448 new_return(23);
8449 }
8450
8451
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8452 {
8453
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8454 {
8455 new_return(24);
8456 }
8457 36864 }
8458
8459
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8460 {
8461
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8462 {
8463 new_return(25);
8464 }
8465 9216 }
8466
8467
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8468 {
8469 new_return(26);
8470 }
8471
8472
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8473 {
8474 new_return(27);
8475 }
8476
8477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8478 {
8479 new_return(28);
8480 }
8481
8482
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8483 {
8484 new_return(29);
8485 }
8486
8487
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8488 {
8489 new_return(30);
8490 }
8491
8492
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8493 {
8494 new_return(31);
8495 }
8496
8497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8498 {
8499 new_return(32);
8500 }
8501
8502
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8503 {
8504 new_return(33);
8505 }
8506
8507
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8508 {
8509 new_return(34);
8510 }
8511
8512
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8513 {
8514 new_return(35);
8515 }
8516
8517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8518 {
8519 new_return(36);
8520 }
8521
8522
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8523 {
8524 new_return(37);
8525 }
8526
8527
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8528 {
8529 new_return(38);
8530 }
8531
8532
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8533 {
8534
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8535 {
8536 new_return(39);
8537 }
8538 9216 }
8539
8540
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8541 {
8542 new_return(40);
8543 }
8544
8545
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8546 {
8547 new_return(41);
8548 }
8549
8550
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8551 {
8552 new_return(42);
8553 }
8554
8555
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8556 {
8557 new_return(43);
8558 }
8559
8560
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8561 {
8562 new_return(44);
8563 }
8564
8565
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8566 {
8567 new_return(45);
8568 }
8569
8570
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8571 {
8572 new_return(46);
8573 }
8574
8575
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8576 {
8577 new_return(47);
8578 }
8579
8580
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8581 {
8582 new_return(48);
8583 }
8584
8585
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8586 {
8587 new_return(48);
8588 }
8589
8590 //New itemdata vars -Z
8591 //! version 27
8592
8593
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8594 {
8595 new_return(51);
8596 }
8597
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8598 {
8599 new_return(52);
8600 }
8601
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8602
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8603 {
8604 new_return(53);
8605 }
8606 46080 }
8607 //version 28
8608
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8609 {
8610 new_return(54);
8611 }
8612
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8613 {
8614
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8615 {
8616 new_return(56);
8617 }
8618 9216 }
8619
8620
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8621 {
8622 new_return(57);
8623 }
8624
8625
8626
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8627 {
8628 new_return(58);
8629 }
8630
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8631 {
8632 new_return(59);
8633 }
8634
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8635 {
8636 new_return(60);
8637 }
8638
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8639 {
8640 new_return(61);
8641 }
8642
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8643 {
8644 new_return(62);
8645 }
8646
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8647 {
8648 new_return(63);
8649 }
8650
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8651 {
8652 new_return(64);
8653 }
8654
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8655 {
8656 new_return(73);
8657 }
8658
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8659 {
8660
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8661 {
8662 new_return(74);
8663 }
8664 9216 }
8665
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8666 {
8667 new_return(75);
8668 }
8669
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8670 {
8671 new_return(76);
8672 }
8673
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8674 {
8675 new_return(77);
8676 }
8677
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8678 {
8679 new_return(81);
8680 }
8681
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8682 {
8683 new_return(82);
8684 }
8685
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8686 {
8687 new_return(83);
8688 }
8689
8690
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8691 {
8692
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8693 {
8694 new_return(84);
8695 }
8696 9216 }
8697
8698 //InitD[] labels
8699
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8700 {
8701
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8702 {
8703
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8704 {
8705 new_return(85);
8706 }
8707 2396160 }
8708
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8709 {
8710
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8711 {
8712 new_return(87);
8713 }
8714 2396160 }
8715
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8716 {
8717 new_return(88);
8718 }
8719 36864 }
8720
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8721 {
8722
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8723 {
8724 new_return(89);
8725 }
8726
8727 9216 }
8728
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8729 {
8730 new_return(90);
8731 }
8732
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8733 {
8734 new_return(91);
8735 }
8736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8737
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8738 new_return(92);
8739
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8740 new_return(95);
8741
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8742 new_return(96);
8743
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8744 new_return(97);
8745
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8746 return ret;
8747
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8748 new_return(98);
8749
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8750
8751
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8752 {
8753 9 section_size=writesize;
8754 9 }
8755 18 }
8756
8757
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8758 {
8759 displayinfo("Error: writeitems()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8760 }
8761
8762 9 new_return(0);
8763 9 }
8764
8765 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8766 {
8767 //these are here to bypass compiler warnings about unused arguments
8768 9 Header=Header;
8769
8770 9 dword section_id=ID_WEAPONS;
8771 9 dword section_version=V_WEAPONS;
8772 9 dword section_size = 0;
8773
8774 //section id
8775
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8776 {
8777 new_return(1);
8778 }
8779
8780 //section version info
8781
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8782 {
8783 new_return(2);
8784 }
8785
8786
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8787 {
8788 new_return(3);
8789 }
8790
8791
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8792 {
8793 18 fake_pack_writing=(writecycle==0);
8794
8795 //section size
8796
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8797 {
8798 new_return(4);
8799 }
8800
8801 18 writesize=0;
8802
8803 //finally... section data
8804
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8805 {
8806 new_return(5);
8807 }
8808
8809
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8810 {
8811
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8812 {
8813 new_return(5);
8814 }
8815 4608 }
8816
8817
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8818 {
8819
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8820 {
8821 new_return(7);
8822 }
8823
8824
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8825 {
8826 new_return(8);
8827 }
8828
8829
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8830 {
8831 new_return(9);
8832 }
8833
8834
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8835 {
8836 new_return(10);
8837 }
8838
8839
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8840 {
8841 new_return(11);
8842 }
8843
8844
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8845 {
8846 new_return(12);
8847 }
8848
8849
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8850 {
8851 new_return(12);
8852 }
8853 4608 }
8854
8855
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8856 {
8857 9 section_size=writesize;
8858 9 }
8859 18 }
8860
8861
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8862 {
8863 displayinfo("Error: writeweapons()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8864 }
8865
8866 9 new_return(0);
8867 }
8868
8869 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8870 {
8871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8872 return qe_invalid;
8873
8874 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8875 12784 bool is_0x80_screen = j >= 0x80;
8876
8877
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8878 return qe_invalid;
8879
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8880 4404 return qe_OK;
8881 //Calculate what needs writing
8882 8380 uint32_t scr_has_flags = 0;
8883
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8884
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8885 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8886
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8887 446 scr_has_flags |= SCRHAS_ITEM;
8888
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8889 28 scr_has_flags |= SCRHAS_TWARP;
8890
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8891 {
8892
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8893
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8894
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8895 {
8896 176 scr_has_flags |= SCRHAS_TWARP;
8897 176 break;
8898 }
8899 32706 }
8900
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8901
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8902 36 scr_has_flags |= SCRHAS_SWARP;
8903
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8904 {
8905
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8906
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8907
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8908 {
8909 4270 scr_has_flags |= SCRHAS_SWARP;
8910 4270 break;
8911 }
8912 16298 }
8913
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8914 44 scr_has_flags |= SCRHAS_WARPRET;
8915
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8916 {
8917
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8918 {
8919 784 scr_has_flags |= SCRHAS_WARPRET;
8920 784 break;
8921 }
8922 30208 }
8923
8924
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8925 scr_has_flags |= SCRHAS_LAYERS;
8926
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8927 {
8928
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8929
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8930 {
8931 966 scr_has_flags |= SCRHAS_LAYERS;
8932 966 break;
8933 }
8934 44532 }
8935
8936
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8937 10 scr_has_flags |= SCRHAS_MAZE;
8938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8939 scr_has_flags |= SCRHAS_MAZE;
8940
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8941 {
8942
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8943 {
8944 scr_has_flags |= SCRHAS_MAZE;
8945 break;
8946 }
8947 33480 }
8948
8949
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8950
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8951
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8952 2968 scr_has_flags |= SCRHAS_D_S_U;
8953
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8954 {
8955
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8956 {
8957 5212 scr_has_flags |= SCRHAS_D_S_U;
8958 5212 break;
8959 }
8960 800 }
8961
8962
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
8963
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
8964
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
8965
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
8966
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
8967
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
8968 8380 scr_has_flags |= SCRHAS_FLAGS;
8969
8970
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
8971 58 scr_has_flags |= SCRHAS_ENEMY;
8972
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
8973 {
8974
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
8975 {
8976 1014 scr_has_flags |= SCRHAS_ENEMY;
8977 1014 break;
8978 }
8979 73086 }
8980
8981
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
8982 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
8983 8380 scr_has_flags |= SCRHAS_CARRY;
8984
8985
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
8986 22 scr_has_flags |= SCRHAS_SCRIPT;
8987
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
8988 {
8989
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
8990 {
8991 scr_has_flags |= SCRHAS_SCRIPT;
8992 break;
8993 }
8994 66864 }
8995
8996
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
8997 {
8998
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
8999
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9000
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9001 {
9002 3076 scr_has_flags |= SCRHAS_SECRETS;
9003 3076 break;
9004 }
9005 680916 }
9006
9007
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9008 {
9009
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9010
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9011 {
9012 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9013 5360 break;
9014 }
9015 568532 }
9016
9017
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9018
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9019
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9020 || screen.timedwarptics || screen.music != -1
9021 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9022 8380 scr_has_flags |= SCRHAS_MISC;
9023
9024
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9025 return qe_invalid;
9026
9027 //Write stuff
9028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9029 {
9030
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9031 return qe_invalid;
9032
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9033 return qe_invalid;
9034
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9035 return qe_invalid;
9036
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9037 return qe_invalid;
9038
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9039 return qe_invalid;
9040
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9041 return qe_invalid;
9042
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9043 return qe_invalid;
9044 8380 }
9045
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9046 {
9047
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9048 return qe_invalid;
9049
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9050 return qe_invalid;
9051
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9052 return qe_invalid;
9053
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9054 return qe_invalid;
9055 446 }
9056
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9057 {
9058
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9059 return qe_invalid;
9060 4374 }
9061
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9062 {
9063
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9064 {
9065
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9066 return qe_invalid;
9067 816 }
9068
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9069 {
9070
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9071 return qe_invalid;
9072 816 }
9073
9074
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9075 {
9076
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9077 return qe_invalid;
9078 816 }
9079
9080
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9081 return qe_invalid;
9082 204 }
9083
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9084 {
9085
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9086 {
9087
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9088 return qe_invalid;
9089 17224 }
9090
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9091 {
9092
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9093 return qe_invalid;
9094 17224 }
9095
9096
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9097 {
9098
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9099 return qe_invalid;
9100 17224 }
9101
9102
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9103 return qe_invalid;
9104
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9105 return qe_invalid;
9106 4306 }
9107
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9108 {
9109
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9110 {
9111
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9112 return qe_invalid;
9113 3312 }
9114
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9115 {
9116
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9117 return qe_invalid;
9118 3312 }
9119
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9120 return qe_invalid;
9121
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9122 return qe_invalid;
9123 828 }
9124
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9125 {
9126
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9127 {
9128
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9129 return qe_invalid;
9130 5796 }
9131
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9132 {
9133
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9134 return qe_invalid;
9135 5796 }
9136
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9137 {
9138
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9139 return qe_invalid;
9140 5796 }
9141
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9142 return qe_invalid;
9143
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9144 return qe_invalid;
9145 966 }
9146
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9147 {
9148
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9149 {
9150
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9151 return qe_invalid;
9152 40 }
9153
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9154 return qe_invalid;
9155
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9156 return qe_invalid;
9157 10 }
9158
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9159 {
9160
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9161 return qe_invalid;
9162
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9163 {
9164
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9165 return qe_invalid;
9166 32720 }
9167
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9168 return qe_invalid;
9169
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9170 return qe_invalid;
9171
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9172 return qe_invalid;
9173
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9174 return qe_invalid;
9175 8180 }
9176
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9177 {
9178
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9179 return qe_invalid;
9180
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9181 return qe_invalid;
9182
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9183 return qe_invalid;
9184
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9185 return qe_invalid;
9186
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9187 return qe_invalid;
9188
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9189 return qe_invalid;
9190
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9191 return qe_invalid;
9192
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9193 return qe_invalid;
9194
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9195 return qe_invalid;
9196
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9197 return qe_invalid;
9198
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9199 return qe_invalid;
9200 1294 }
9201
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9202 {
9203
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9204 {
9205
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9206 return qe_invalid;
9207 10720 }
9208
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9209 return qe_invalid;
9210 1072 }
9211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9212 {
9213
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9214 return qe_invalid;
9215
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9216 return qe_invalid;
9217
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9218 return qe_invalid;
9219
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9220 return qe_invalid;
9221
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9222 return qe_invalid;
9223
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9224 return qe_invalid;
9225 8380 }
9226
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9227 {
9228
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9231 return qe_invalid;
9232
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9233 {
9234
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9235 return qe_invalid;
9236 176 }
9237 22 }
9238
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9239 {
9240
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9241 {
9242
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9243 return qe_invalid;
9244 393728 }
9245
9246
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9247 {
9248
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9249 return qe_invalid;
9250 393728 }
9251
9252
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9253 {
9254
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9255 return qe_invalid;
9256 393728 }
9257 3076 }
9258
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9259 {
9260
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9261 {
9262
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9263 return qe_invalid;
9264 943360 }
9265
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9266 {
9267
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9268 return qe_invalid;
9269 943360 }
9270
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9271 {
9272
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9273 return qe_invalid;
9274 943360 }
9275 5360 }
9276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9277 {
9278
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9279 return qe_invalid;
9280
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9281 return qe_invalid;
9282
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9283 return qe_invalid;
9284
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9285 return qe_invalid;
9286
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9287 return qe_invalid;
9288
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9289 return qe_invalid;
9290
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9291 return qe_invalid;
9292
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.music,f))
9293 return qe_invalid;
9294
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9295 return qe_invalid;
9296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9297 return qe_invalid;
9298
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9299 return qe_invalid;
9300 8380 }
9301
9302 8380 dword numffc = screen.numFFC();
9303
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9304 return qe_invalid;
9305
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9306 {
9307 245678 ffcdata const& tempffc = screen.ffcs[k];
9308
9309
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9310 return qe_invalid;
9311
9312
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9313 243364 continue;
9314
9315
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9316 return qe_invalid;
9317
9318
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9319 return qe_invalid;
9320
9321
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9322 return qe_invalid;
9323
9324
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9325 return qe_invalid;
9326
9327
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9328 return qe_invalid;
9329
9330
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9331 return qe_invalid;
9332
9333
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9334 return qe_invalid;
9335
9336
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9337 return qe_invalid;
9338
9339
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9340 return qe_invalid;
9341
9342
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9343 return qe_invalid;
9344
9345
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9346 return qe_invalid;
9347
9348
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9349 return qe_invalid;
9350
9351
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9352 return qe_invalid;
9353
9354
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9355 return qe_invalid;
9356
9357
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9358 return qe_invalid;
9359
9360
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9361 {
9362
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9363 return qe_invalid;
9364 18512 }
9365
9366
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9367 return qe_invalid;
9368 2314 }
9369
9370
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9371 return qe_invalid;
9372
9373
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9374 {
9375
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9376 return qe_invalid;
9377
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9378 return qe_invalid;
9379 6 }
9380
9381 8380 return qe_OK;
9382 12784 }
9383
9384 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9385 {
9386 9 dword section_id=ID_MAPS;
9387 9 dword section_version=V_MAPS;
9388 9 dword section_size = 0;
9389
9390 //section id
9391
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9392 {
9393 new_return(1);
9394 }
9395
9396 //section version info
9397
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9398 {
9399 new_return(2);
9400 }
9401
9402
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9403 {
9404 new_return(3);
9405 }
9406
9407
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9408 {
9409 18 fake_pack_writing=(writecycle==0);
9410
9411 //section size
9412
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9413 {
9414 new_return(4);
9415 }
9416
9417 18 writesize=0;
9418
9419
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9420 {
9421 new_return(5);
9422 }
9423 18 map_infos.resize(map_count);
9424
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 100 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9425 {
9426 100 byte valid = 0;
9427
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9428 {
9429
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9430 break;
9431 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9432
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9433 {
9434 94 valid = 1;
9435 94 break;
9436 }
9437 1188 }
9438
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9439 {
9440 new_return(6);
9441 }
9442
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9443
9444 { //per-map info
9445 94 auto const& mapinf = map_infos[i];
9446
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9447 {
9448
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9449 new_return(7);
9450 564 }
9451
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9452 new_return(9);
9453
9454
9455
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9456 {
9457
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9458 {
9459
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9460 {
9461 new_return(8);
9462 }
9463 6016 }
9464 752 }
9465 }
9466
9467
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9468 12784 writemapscreen(f,i,j);
9469 94 }
9470
9471
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9472 {
9473 9 section_size=writesize;
9474 9 }
9475 18 }
9476
9477
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9478 {
9479 displayinfo("Error: writemaps()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
9480 }
9481
9482 9 new_return(0);
9483 }
9484
9485 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9486 {
9487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9488 return 22;
9489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9490 return 22;
9491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9492 return 23;
9493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9494 return 34;
9495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9496 return 35;
9497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9498 return 36;
9499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9500 return 37;
9501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9502 return 38;
9503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9504 return 39;
9505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9506 return 40;
9507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9508 return 41;
9509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9510 return 42;
9511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9512 return 43;
9513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9514 return 44;
9515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9516 return 45;
9517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9518 return 46;
9519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9520 return 47;
9521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9522 return 48;
9523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9524 return 49;
9525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9526 return 50;
9527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9528 return 51;
9529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9530 return 52;
9531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9532 return 53;
9533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9534 return 69;
9535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9536 return 70;
9537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9538 return 71;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9540 return 72;
9541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9542 return 76;
9543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9544 return 77;
9545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9546 return 89;
9547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9548 return 90;
9549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9550 return 91;
9551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9552 return 92;
9553
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9555 return 93;
9556
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9557 return 94;
9558
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9559 return 95;
9560
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9561 return 96;
9562
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9563 return 97;
9564
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9565 return 98;
9566
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9567 return 99;
9568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9569 return 100;
9570
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9571 return 101;
9572
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9573 return 102;
9574
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9575 return 103;
9576
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9577 return 104;
9578
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9579 return 105;
9580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9581 return 106;
9582
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9583 return 107;
9584
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9585 return 108;
9586
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9587 return 109;
9588
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9589 return 110;
9590
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9591 return 111;
9592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9593 return 112;
9594
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9595 return 113;
9596
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9597 return 114;
9598
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9599 return 115;
9600
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9601 return 116;
9602
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9603 return 117;
9604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9605 return 118;
9606
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9607 return 119;
9608
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9609 return 120;
9610
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9611 return 121;
9612
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9613 return 122;
9614
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9615 return 123;
9616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9617 return 124;
9618
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9619 return 125;
9620
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9621 return 126;
9622
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_state, f))
9623 return 127;
9624
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_state, f))
9625 return 128;
9626
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_ex_state, f))
9627 return 129;
9628
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_ex_state, f))
9629 return 130;
9630
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatemap, f))
9631 return 131;
9632
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatescreen, f))
9633 return 132;
9634
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.play_music, f))
9635 return 133;
9636
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.set_music_refresh, f))
9637 return 134;
9638 460 return 0;
9639 460 }
9640 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9641 {
9642 //Check what needs writing
9643 258906 word combo_has_flags = 0;
9644
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 6161326 times.
6417042 for(auto q = 0; q < NUM_COMBO_ATTRIBUTES; ++q)
9645 {
9646
2/2
✓ Branch 0 taken 6158136 times.
✓ Branch 1 taken 3190 times.
6161326 if(tmp_cmb.c_attributes[q])
9647 {
9648 3190 combo_has_flags |= CHAS_ATTRIB;
9649 3190 break;
9650 }
9651 6158136 }
9652
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9653 460 combo_has_flags |= CHAS_TRIG;
9654
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9655 298 combo_has_flags |= CHAS_FLAG;
9656
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9657
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9658
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9659 28174 combo_has_flags |= CHAS_ANIM;
9660
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258900 times.
✓ Branch 3 taken 6 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9661 6 combo_has_flags |= CHAS_SCRIPT;
9662
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9663 {
9664
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9665 {
9666 combo_has_flags |= CHAS_SCRIPT;
9667 break;
9668 }
9669 2071200 }
9670
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9671
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9672 82514 combo_has_flags |= CHAS_BASIC;
9673
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9674
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9675
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9676
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9677
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9678
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9679
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9680 10 combo_has_flags |= CHAS_LIFT;
9681
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9682
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9683
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9684
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9685
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9686
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9687 258906 combo_has_flags |= CHAS_GENERAL;
9688
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9689 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9690
9691
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9692 {
9693 return 50;
9694 }
9695
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9696 //Write the combo
9697
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9698 {
9699
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9700 return 6;
9701
9702
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9703 return 7;
9704
9705
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9706 return 8;
9707
9708
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9709 return 9;
9710
9711
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9712 return 15;
9713
9714
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9715 return 10;
9716 82514 }
9717
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9718 {
9719 6 p_putcstr(tmp_cmb.label, f);
9720
9721
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9722 return 26;
9723
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9724
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9725 return 27;
9726 6 }
9727
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9728 {
9729
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9730 return 11;
9731
9732
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9733 return 12;
9734
9735
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9736 return 13;
9737
9738
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9739 return 14;
9740
9741
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9742 return 16;
9743
9744
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9745 return 18;
9746
9747
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9748 return 19;
9749 28174 }
9750
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9751 {
9752
1/2
✓ Branch 0 taken 3190 times.
✗ Branch 1 not taken.
3190 if (!p_iputw(NUM_COMBO_ATTRIBUTES, f))
9753 return 25;
9754
2/2
✓ Branch 0 taken 76560 times.
✓ Branch 1 taken 3190 times.
79750 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
9755
1/2
✓ Branch 0 taken 76560 times.
✗ Branch 1 not taken.
76560 if(!p_iputzf(tmp_cmb.c_attributes[q],f))
9756 return 20;
9757 3190 }
9758
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9759 {
9760
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9761 return 21;
9762
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9763 return 33;
9764 298 }
9765
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9766 {
9767
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9768
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9769 return 34;
9770
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9771 {
9772 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9773
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9774 460 }
9775
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9776 return 35;
9777 460 }
9778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9779 {
9780
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9781 return 54;
9782
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9783 return 55;
9784
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9785 return 56;
9786
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9787 return 57;
9788
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9789 return 58;
9790
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9791 return 59;
9792
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9793 return 60;
9794
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9795 return 61;
9796
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9797 return 62;
9798
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9799 return 63;
9800
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9801 return 64;
9802
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9803 return 65;
9804
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9805 return 66;
9806
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9807 return 67;
9808
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9809 return 68;
9810
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9811 return 78;
9812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9813 return ret;
9814 258906 }
9815
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9816 {
9817
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9818 return 73;
9819
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9820 return 74;
9821
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9822 return 75;
9823
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9824 return 79;
9825
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9826 return 80;
9827
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9828 return 81;
9829
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9830 return 82;
9831
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9832 return 83;
9833
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9834 return 84;
9835
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9836 return 85;
9837
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9838 return 86;
9839
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9840 return 87;
9841
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9842 return 88;
9843
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9844 return 89;
9845
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9846 return 90;
9847
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9848 return 91;
9849
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9850 return 92;
9851
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9852 return 93;
9853
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9854 return 94;
9855
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9856 return 95;
9857
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9858 return 96;
9859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9860 return 97;
9861
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9862 return 98;
9863 2200 }
9864
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9865 {
9866 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9867 return ret;
9868 }
9869 258906 return 0;
9870 258906 }
9871
9872 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9873 {
9874 //these are here to bypass compiler warnings about unused arguments
9875 9 version=version;
9876 9 build=build;
9877
9878 word combos_used;
9879 9 dword section_id=ID_COMBOS;
9880 9 dword section_version=V_COMBOS;
9881 // dword section_size=0;
9882 9 combos_used = count_combos()-start_combo;
9883
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9884
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9885 9 dword section_size = 0;
9886
9887 //section id
9888
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9889 {
9890 new_return(1);
9891 }
9892
9893 //section version info
9894
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9895 {
9896 new_return(2);
9897 }
9898
9899
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9900 {
9901 new_return(3);
9902 }
9903
9904
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9905 {
9906 18 fake_pack_writing=(writecycle==0);
9907
9908 //section size
9909
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9910 {
9911 new_return(4);
9912 }
9913
9914 18 writesize=0;
9915
9916 //finally... section data
9917 18 combos_used=count_combos()-start_combo;
9918
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9919
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9920
9921
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9922 {
9923 new_return(5);
9924 }
9925
9926 18 size_t end_combo = start_combo+combos_used;
9927
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9928 {
9929 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9930
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9931 258906 }
9932
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9933 {
9934 9 section_size=writesize;
9935 9 }
9936 18 }
9937
9938
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9939 {
9940 displayinfo("Error: writecombos()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
9941 }
9942
9943 9 new_return(0);
9944 9 }
9945
9946 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9947 {
9948 //these are here to bypass compiler warnings about unused arguments
9949 9 version=version;
9950 9 build=build;
9951
9952 9 dword section_id=ID_COMBOALIASES;
9953 9 dword section_version=V_COMBOALIASES;
9954 9 dword section_size=0;
9955
9956 //section id
9957
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9958 {
9959 new_return(1);
9960 }
9961
9962 //section version info
9963
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9964 {
9965 new_return(2);
9966 }
9967
9968
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9969 {
9970 new_return(3);
9971 }
9972
9973
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9974 {
9975 18 fake_pack_writing=(writecycle==0);
9976
9977 //section size
9978
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9979 {
9980 new_return(4);
9981 }
9982
9983 18 writesize=0;
9984
9985 //finally... section data
9986
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9987 {
9988
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9989 {
9990 new_return(5);
9991 }
9992
9993
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9994 {
9995 new_return(6);
9996 }
9997
9998 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9999
10000
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
10001 {
10002 new_return(7);
10003 }
10004
10005
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
10006 {
10007 new_return(8);
10008 }
10009
10010
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10011 {
10012 new_return(9);
10013 }
10014
10015
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10016 {
10017
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10018 {
10019 new_return(10);
10020 }
10021 149596 }
10022
10023
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 149596 times.
297052 for(int32_t k=0; k<count; k++)
10024 {
10025
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10026 {
10027 new_return(11);
10028 }
10029 149596 }
10030 147456 }
10031
10032 //Combo pools!
10033 int16_t num_cpools;
10034
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10035 {
10036
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10037 {
10038 2 ++num_cpools;
10039 2 break;
10040 }
10041 147450 }
10042
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10043
10044
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10045 {
10046 new_return(12);
10047 }
10048
10049
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10050 {
10051 6 combo_pool const& pool = combo_pools[cp];
10052 6 int32_t num_combos = pool.combos.size();
10053
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10054 {
10055 new_return(13);
10056 }
10057
10058
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10059 {
10060 26 cpool_entry const& entry = pool.combos.at(q);
10061
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10062 {
10063 new_return(14);
10064 }
10065
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10066 {
10067 new_return(15);
10068 }
10069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if(!p_iputw(entry.quant,f))
10070 {
10071 new_return(16);
10072 }
10073 26 }
10074 6 }
10075
10076 //Autocombos!
10077 int16_t num_cautos;
10078
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10079 {
10080
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10081 {
10082 ++num_cautos;
10083 break;
10084 }
10085 147456 }
10086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10087
10088
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10089 {
10090 new_return(17);
10091 }
10092
10093
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10094 {
10095 combo_auto const& cauto = combo_autos[ca];
10096 if (!p_putc(cauto.getType(), f))
10097 {
10098 new_return(18);
10099 }
10100 if (!p_iputl(cauto.getIconDisplay(), f))
10101 {
10102 new_return(19);
10103 }
10104 if (!p_iputl(cauto.getEraseCombo(), f))
10105 {
10106 new_return(20);
10107 }
10108 if (!p_putc(cauto.getFlags(), f))
10109 {
10110 new_return(21);
10111 }
10112 if (!p_putc(cauto.getArg(), f))
10113 {
10114 new_return(22);
10115 }
10116 int32_t num_combos = cauto.combos.size();
10117 if (!p_iputl(num_combos, f))
10118 {
10119 new_return(23);
10120 }
10121
10122 for (auto q = 0; q < num_combos; ++q)
10123 {
10124 autocombo_entry const& entry = cauto.combos.at(q);
10125 if (!p_putc(entry.ctype, f))
10126 {
10127 new_return(24);
10128 }
10129 if (!p_iputl(entry.cid, f))
10130 {
10131 new_return(25);
10132 }
10133 }
10134 }
10135
10136
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10137 {
10138 9 section_size=writesize;
10139 9 }
10140 18 }
10141
10142
10143
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10144 {
10145 displayinfo("Error: writecomboaliases()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10146 }
10147
10148 9 new_return(0);
10149 }
10150
10151 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10152 {
10153 //these are here to bypass compiler warnings about unused arguments
10154 9 version=version;
10155 9 build=build;
10156 9 start_cset=start_cset;
10157 9 max_csets=max_csets;
10158
10159 9 dword section_id=ID_CSETS;
10160 9 dword section_version=V_CSETS;
10161 9 int32_t palcycles = count_palcycles(&QMisc);
10162 // int32_t palcyccount = count_palcycles(&QMisc);
10163 9 dword section_size = 0;
10164
10165 //section id
10166
10167
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10168 {
10169 new_return(1);
10170 }
10171
10172 //section version info
10173
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10174 {
10175 new_return(2);
10176 }
10177
10178
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10179 {
10180 new_return(3);
10181 }
10182
10183
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10184 {
10185 18 fake_pack_writing=(writecycle==0);
10186
10187 //section size
10188
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10189 {
10190 new_return(4);
10191 }
10192
10193 18 writesize=0;
10194
10195 //finally... section data
10196
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10197 {
10198 new_return(5);
10199 }
10200
10201
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10202 {
10203 new_return(6);
10204 }
10205
10206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(palcycles,f))
10207 {
10208 new_return(15);
10209 }
10210
10211
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10212 {
10213
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10214 {
10215
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10216 {
10217 new_return(16);
10218 }
10219 1650 }
10220
10221
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10222 {
10223
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10224 {
10225 new_return(17);
10226 }
10227 1650 }
10228
10229
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 1650 times.
2200 for(int32_t j=0; j<3; j++)
10230 {
10231
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10232 {
10233 new_return(18);
10234 }
10235 1650 }
10236 550 }
10237
10238
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10239 {
10240 9 section_size=writesize;
10241 9 }
10242 18 }
10243
10244
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10245 {
10246 displayinfo("Error: writecolordata()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10247 }
10248
10249 9 new_return(0);
10250 }
10251
10252 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10253 {
10254 //these are here to bypass compiler warnings about unused arguments
10255 9 version=version;
10256 9 build=build;
10257 9 start_msgstr=start_msgstr;
10258 9 max_msgstrs=max_msgstrs;
10259
10260 9 dword section_id=ID_STRINGS;
10261 9 dword section_version=V_STRINGS;
10262 9 dword section_size = 0;
10263
10264 //section id
10265
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10266 {
10267 new_return(1);
10268 }
10269
10270 //section version info
10271
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10272 {
10273 new_return(2);
10274 }
10275
10276
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10277 {
10278 new_return(3);
10279 }
10280
10281
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10282 {
10283 18 fake_pack_writing=(writecycle==0);
10284
10285 //section size
10286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10287 {
10288 new_return(4);
10289 }
10290
10291 18 writesize=0;
10292
10293 //finally... section data
10294
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10295 {
10296 return qe_invalid;
10297 }
10298
10299
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10300 {
10301 836 MsgStrings[i].ensureAsciiEncoding();
10302 836 int32_t sz = MsgStrings[i].s.size();
10303
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10304
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10305 {
10306 return qe_invalid;
10307 }
10308
10309 836 char const* tmpstr = MsgStrings[i].s.c_str();
10310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10311 {
10312
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10313 {
10314 return qe_invalid;
10315 }
10316 836 }
10317
10318
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10319 {
10320 return qe_invalid;
10321 }
10322
10323
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10324 {
10325 return qe_invalid;
10326 }
10327
10328
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10329 {
10330 return qe_invalid;
10331 }
10332
10333
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10334 {
10335 return qe_invalid;
10336 }
10337
10338
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10339 {
10340 return qe_invalid;
10341 }
10342
10343
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10344 {
10345 return qe_invalid;
10346 }
10347
10348
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10349 {
10350 return qe_invalid;
10351 }
10352
10353
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10354 {
10355 return qe_invalid;
10356 }
10357
10358
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10359 {
10360 return qe_invalid;
10361 }
10362
10363
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10364 {
10365 return qe_invalid;
10366 }
10367
10368
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10369 {
10370 return qe_invalid;
10371 }
10372
10373
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10374 {
10375 return qe_invalid;
10376 }
10377
10378
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10379 {
10380
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10381 {
10382 return qe_invalid;
10383 }
10384 3344 }
10385
10386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10387 {
10388 return qe_invalid;
10389 }
10390
10391
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10392 {
10393 return qe_invalid;
10394 }
10395
10396
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10397 {
10398 return qe_invalid;
10399 }
10400
10401
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10402 {
10403 return qe_invalid;
10404 }
10405
10406
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10407 {
10408 return qe_invalid;
10409 }
10410
10411
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10412 {
10413 return qe_invalid;
10414 }
10415
10416
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10417 {
10418 return qe_invalid;
10419 }
10420
10421
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10422 {
10423 return qe_invalid;
10424 }
10425
10426
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10427 {
10428 return qe_invalid;
10429 }
10430
10431
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10432 {
10433 return qe_invalid;
10434 }
10435
10436
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10437 {
10438 return qe_invalid;
10439 }
10440 836 }
10441
10442
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10443 {
10444 9 section_size=writesize;
10445 9 }
10446 18 }
10447
10448
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10449 {
10450 displayinfo("Error: writestrings()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10451 }
10452
10453 9 new_return(0);
10454 9 }
10455
10456 int32_t writestrings_text(PACKFILE *f)
10457 {
10458 std::map<int32_t, int32_t> msglistcache;
10459
10460 for(int32_t index = 1; index<msg_count; index++)
10461 {
10462 for(int32_t i=1; i<msg_count; i++)
10463 {
10464 if(MsgStrings[i].listpos==index)
10465 {
10466 msglistcache[index-1]=i;
10467 break;
10468 }
10469 }
10470 }
10471
10472 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10473 {
10474 fake_pack_writing=(writecycle==0);
10475 char ebuf[32];
10476
10477 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10478
10479 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10480 {
10481 return qe_invalid;
10482 }
10483
10484 for(int32_t i=1; i<msg_count; i++)
10485 {
10486 int32_t str = msglistcache[i-1];
10487
10488 if(!str)
10489 continue;
10490
10491 if(MsgStrings[str].nextstring != 0)
10492 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10493 else
10494 sprintf(ebuf,"\n\n___%d___\n", str);
10495
10496 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10497 {
10498 return qe_invalid;
10499 }
10500
10501 std::string text = MsgStrings[str].serialize();
10502 if (!pfwrite(text.c_str(), text.size(), f))
10503 {
10504 return qe_invalid;
10505 }
10506 }
10507 }
10508
10509 new_return(0);
10510 }
10511
10512 1 int32_t writestrings_tsv(PACKFILE *f)
10513 {
10514 1 std::stringstream ss;
10515
10516
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10517
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10518
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10520
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10521
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10522
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10523
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10524
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10525
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10526
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10527
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10528
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10529
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10530
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10531
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10532
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10533
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10534
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10535
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10536
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10537
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10538
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10539
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10540
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10541
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10542 };
10543
10544
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10545 {
10546
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10547
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10548 1 break;
10549
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10550 }
10551
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10552
10553 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10554
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10555
10556
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10557 {
10558 35 auto& msg = MsgStrings[i];
10559
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10560 {
10561
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10562
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10563
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10564 35 break;
10565
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10566
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10567
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10568 35 }
10569
10570
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10571
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10572 {
10573 return qe_invalid;
10574 }
10575
10576 1 new_return(0);
10577 1 }
10578
10579 void parse_strings_tsv(std::string tsv)
10580 {
10581 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10582 { "message", [](auto& msg, auto& text){ msg.setFromAsciiEncoding(text); } },
10583 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10584 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10585 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10586 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10587 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10588 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10589 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10590 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10591 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10592 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10593 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10594 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10595 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10596 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10597 { "margin", [&](auto& msg, auto& text){
10598 std::vector<std::string> strs;
10599 util::split(text, strs, ' ');
10600 if (strs.size() != 4)
10601 throw std::runtime_error("margin field must have 4 components");
10602 msg.margins[0] = std::stoi(strs[0]);
10603 msg.margins[1] = std::stoi(strs[1]);
10604 msg.margins[2] = std::stoi(strs[2]);
10605 msg.margins[3] = std::stoi(strs[3]);
10606 } },
10607 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10608 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10609 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10610 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10611 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10612 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10613 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10614 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10615 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10616 };
10617
10618 std::vector<std::string> rows;
10619 util::split(tsv, rows, '\n');
10620 if (rows.size())
10621 {
10622 std::string last = rows.back();
10623 util::trimstr(last);
10624 if (last.empty())
10625 rows.pop_back();
10626 }
10627 if (rows.size() <= 1)
10628 throw std::runtime_error("missing header row");
10629
10630 std::vector<std::string> columns;
10631 util::split(rows[0], columns, '\t');
10632 for (auto name : columns)
10633 {
10634 if (!fields.contains(name))
10635 throw std::runtime_error(fmt::format("invalid field: {}", name));
10636 }
10637
10638 int start_index = 1;
10639 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10640 start_index += 1;
10641
10642 int num_strings = rows.size() - start_index + 1;
10643 if (num_strings > MAXMSGS-1)
10644 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10645
10646 std::vector<MsgStr> msgs;
10647 msgs.reserve(num_strings);
10648 for (int i = start_index; i < rows.size(); i++)
10649 {
10650 std::vector<std::string> strs;
10651 util::split(rows[i], strs, '\t');
10652 if (strs.size() != columns.size())
10653 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10654
10655 int j = 0;
10656 auto& msg = msgs.emplace_back();
10657 for (auto& name : columns)
10658 {
10659 auto& fn = fields[name];
10660 try
10661 {
10662 fn(msg, strs[j++]);
10663 }
10664 catch (std::exception& ex)
10665 {
10666 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10667 }
10668 }
10669 }
10670
10671 init_msgstrings(0, msgs.size());
10672 for (int i = 0; i < msgs.size(); i++)
10673 MsgStrings[i + 1] = msgs[i];
10674 msg_count = msgs.size() + 1;
10675 msglistcache.clear();
10676 }
10677
10678 bool isblanktile(tiledata *buf, int32_t i);
10679 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10680 {
10681 //these are here to bypass compiler warnings about unused arguments
10682 9 version=version;
10683 9 build=build;
10684
10685 int32_t tiles_used;
10686 9 dword section_id=ID_TILES;
10687 9 dword section_version=V_TILES;
10688 9 al_trace("Counting tiles used\n");
10689 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10691
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10692 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10693 9 dword section_size = 0;
10694
10695 //section id
10696
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10697 {
10698 new_return(1);
10699 }
10700
10701 //section version info
10702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10703 {
10704 new_return(2);
10705 }
10706
10707
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10708 {
10709 new_return(3);
10710 }
10711
10712
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10713 {
10714 18 fake_pack_writing=(writecycle==0);
10715
10716 //section size
10717
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10718 {
10719 new_return(4);
10720 }
10721
10722 18 writesize=0;
10723
10724 //finally... section data
10725 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10726
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10727
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10728
10729
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10730 {
10731 new_return(5);
10732 }
10733
10734
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10735 {
10736
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10737 {
10738
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10739 new_return(8);
10740 365770 }
10741 else
10742 {
10743 330614 int format = newtilebuf[start_tile+i].format;
10744
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10745 {
10746 new_return(6);
10747 }
10748
10749
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10750 {
10751 byte temp_tile[128];
10752 327742 byte *di = temp_tile;
10753 327742 byte *src = newtilebuf[start_tile+i].data;
10754
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10755 {
10756 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10757 41950976 ++di;
10758 41950976 }
10759
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10760 {
10761 new_return(7);
10762 }
10763 327742 }
10764
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10765 {
10766 new_return(7);
10767 }
10768 }
10769 696384 }
10770
10771
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10772 {
10773 9 section_size=writesize;
10774 9 }
10775 18 }
10776
10777
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10778 {
10779 displayinfo("Error: writetiles()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10780 }
10781
10782 9 new_return(0);
10783 }
10784
10785 /* MIDI Format
10786 section_id LONG
10787 section_version WORD
10788 section_cversion WORD
10789 section_size LONG
10790 midi_flags bitstring
10791
10792 [
10793 title 36
10794 start 4
10795 loop_start 4
10796 loop_end 4
10797 loop 2
10798 volume 2
10799 midi *
10800 ]
10801
10802 */
10803
10804 9 int32_t writemidis(PACKFILE *f)
10805 {
10806 9 dword section_id=ID_MIDIS;
10807 9 dword section_version=V_MIDIS;
10808 9 dword section_size = 0;
10809 9 bitstring midi_bitstr;
10810 9 word tune_count = 0;
10811
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 4608 times.
4617 for(uint q = 0; q < MAXCUSTOMMIDIS; q++)
10812 {
10813
2/2
✓ Branch 0 taken 4543 times.
✓ Branch 1 taken 65 times.
4608 if (customtunes[q].data)
10814 {
10815 65 tune_count = q+1; // iterating up to this count will include the highest valid tune
10816
1/2
✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
65 midi_bitstr.set(q, true);
10817 65 }
10818 4608 }
10819
10820 //section id
10821
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(!p_mputl(section_id,f))
10822 {
10823 new_return(1);
10824 }
10825
10826 //section version info
10827
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(!p_iputw(section_version,f))
10828 {
10829 new_return(2);
10830 }
10831
10832
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10833 {
10834 new_return(3);
10835 }
10836
10837
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10838 {
10839 18 fake_pack_writing=(writecycle==0);
10840
10841 //section size
10842
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 if(!p_iputl(section_size,f))
10843 {
10844 new_return(4);
10845 }
10846
10847 18 writesize=0;
10848
10849 //finally... section data
10850
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 if (!p_putbitstr(midi_bitstr, f))
10851 new_return(5);
10852
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 if (!p_iputw(tune_count, f))
10853 new_return(5);
10854
10855
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 18 times.
148 for(uint i = 0; i < tune_count; ++i)
10856 {
10857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(customtunes[i].data)
10858 {
10859
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if (!p_putwstr(customtunes[i].song_title,f))
10860 new_return(6);
10861
10862
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10863 new_return(7);
10864
10865
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10866 new_return(8);
10867
10868
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10869 new_return(9);
10870
10871
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10872 new_return(10);
10873
10874
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10875 new_return(11);
10876
10877
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10878 new_return(12);
10879
10880 130 byte format = MFORMAT_MIDI;
10881
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10882 new_return(13);
10883
10884
2/4
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
130 if (!write_midi(customtunes[i].data, f))
10885 new_return(14);
10886 130 }
10887 130 }
10888
10889
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10890 9 section_size=writesize;
10891 18 }
10892
10893
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10894 {
10895 displayinfo("Error: writemidis()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10896 }
10897
10898 9 new_return(0);
10899 9 }
10900
10901 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10902 {
10903 9 dword section_id=ID_CHEATS;
10904 9 dword section_version=V_CHEATS;
10905 9 dword section_size = 0;
10906
10907 //section id
10908
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10909 {
10910 new_return(1);
10911 }
10912
10913 //section version info
10914
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10915 {
10916 new_return(2);
10917 }
10918
10919
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10920 {
10921 new_return(3);
10922 }
10923
10924
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10925 {
10926 18 fake_pack_writing=(writecycle==0);
10927
10928 //section size
10929
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10930 {
10931 new_return(4);
10932 }
10933
10934 18 writesize=0;
10935
10936 //finally... section data
10937
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10938 {
10939 new_return(5);
10940 }
10941
10942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10943 {
10944
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10945 {
10946 new_return(6);
10947 }
10948
10949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10950 {
10951 new_return(7);
10952 }
10953 18 }
10954
10955
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10956 {
10957 9 section_size=writesize;
10958 9 }
10959 18 }
10960
10961
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10962 {
10963 displayinfo("Error: writecheats()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10964 }
10965
10966 9 new_return(0);
10967 }
10968
10969 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10970 {
10971 //these are here to bypass compiler warnings about unused arguments
10972 9 Header=Header;
10973
10974 9 dword section_id=ID_GUYS;
10975 9 dword section_version=V_GUYS;
10976 9 dword section_size=0;
10977
10978 //section id
10979
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10980 {
10981 new_return(1);
10982 }
10983
10984 //section version info
10985
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10986 {
10987 new_return(2);
10988 }
10989
10990
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10991 {
10992 new_return(3);
10993 }
10994
10995
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10996 {
10997 18 fake_pack_writing=(writecycle==0);
10998
10999 //section size
11000
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11001 {
11002 new_return(4);
11003 }
11004
11005 18 writesize=0;
11006
11007 //finally... section data
11008
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11009 {
11010
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11011 {
11012 new_return(5);
11013 }
11014 9216 }
11015
11016
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11017 {
11018 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11019 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11020
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11021 {
11022 new_return(6);
11023 }
11024
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11025 {
11026 new_return(7);
11027 }
11028
11029
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11030 {
11031 new_return(8);
11032 }
11033
11034
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11035 {
11036 new_return(9);
11037 }
11038
11039
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11040 {
11041 new_return(10);
11042 }
11043
11044
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11045 {
11046 new_return(11);
11047 }
11048
11049
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11050 {
11051 new_return(12);
11052 }
11053
11054
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11055 {
11056 new_return(13);
11057 }
11058
11059
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11060 {
11061 new_return(14);
11062 }
11063
11064
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11065 {
11066 new_return(15);
11067 }
11068
11069
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11070 {
11071 new_return(16);
11072 }
11073
11074
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11075 {
11076 new_return(17);
11077 }
11078
11079
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11080 {
11081 new_return(18);
11082 }
11083
11084
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11085 {
11086 new_return(19);
11087 }
11088
11089
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11090 {
11091 new_return(20);
11092 }
11093
11094
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11095 {
11096 new_return(21);
11097 }
11098
11099
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11100 {
11101 new_return(22);
11102 }
11103
11104
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11105 {
11106 new_return(23);
11107 }
11108
11109
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11110 {
11111 new_return(24);
11112 }
11113
11114
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11115 {
11116 new_return(25);
11117 }
11118
11119
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11120 {
11121 new_return(26);
11122 }
11123
11124
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11125 {
11126 new_return(27);
11127 }
11128
11129
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11130 {
11131 new_return(28);
11132 }
11133
11134
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11135 {
11136 new_return(29);
11137 }
11138
11139
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11140 {
11141 new_return(30);
11142 }
11143
11144
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11145 {
11146 new_return(31);
11147 }
11148
11149
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11150 {
11151 new_return(32);
11152 }
11153
11154
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11155 {
11156 new_return(33);
11157 }
11158
11159
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11160 {
11161 new_return(34);
11162 }
11163
11164
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11165 {
11166 new_return(35);
11167 }
11168
11169
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11170 {
11171 new_return(36);
11172 }
11173
11174
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11175 {
11176 new_return(37);
11177 }
11178
11179
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11180 {
11181 new_return(38);
11182 }
11183
11184
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11185 {
11186 new_return(39);
11187 }
11188
11189
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11190 {
11191 new_return(40);
11192 }
11193
11194
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11195 {
11196 new_return(41);
11197 }
11198
11199
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11200 {
11201 new_return(42);
11202 }
11203
11204
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11205 {
11206 new_return(43);
11207 }
11208
11209
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11210 {
11211 new_return(44);
11212 }
11213
11214
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11215 {
11216 new_return(45);
11217 }
11218
11219
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11220 {
11221
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11222 {
11223 new_return(46);
11224 }
11225 175104 }
11226
11227
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11228 {
11229 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11231 //Force SFX_HIT here.
11232
11233 2048 }
11234
11235
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11236 {
11237 new_return(47);
11238 }
11239
11240
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11241 {
11242 new_return(48);
11243 }
11244
11245
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11246 {
11247 new_return(49);
11248 }
11249
11250
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11251 {
11252 new_return(50);
11253 }
11254
11255 //New 2.6 defences
11256
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11257 {
11258
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11259 {
11260 new_return(51);
11261 }
11262 202752 }
11263
11264 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11265
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11266 {
11267 new_return(52);
11268 }
11269
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11270 {
11271 new_return(53);
11272 }
11273
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11274 {
11275 new_return(54);
11276 }
11277
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11278 {
11279 new_return(55);
11280 }
11281
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11282 {
11283 new_return(56);
11284 }
11285 // These are not fixed types, but ints, so they are safe to use here.
11286
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11287 {
11288 new_return(57);
11289 }
11290
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11291 {
11292 new_return(58);
11293 }
11294
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11295 {
11296 new_return(59);
11297 }
11298
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11299 {
11300 new_return(60);
11301 }
11302
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11303 {
11304 new_return(61);
11305 }
11306
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11307 {
11308 new_return(62);
11309 }
11310
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11311 {
11312 new_return(63);
11313 }
11314
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11315 {
11316 new_return(64);
11317 }
11318
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11319 {
11320 new_return(65);
11321 }
11322
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11323 {
11324 new_return(66);
11325 }
11326
11327
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11328 {
11329
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11330 {
11331 new_return(67);
11332 }
11333 92160 }
11334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11335 {
11336 new_return(68);
11337 }
11338 //misc 16->31
11339
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11340 {
11341 new_return(69);
11342 }
11343
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11344 {
11345 new_return(70);
11346 }
11347
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11348 {
11349 new_return(71);
11350 }
11351
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11352 {
11353 new_return(72);
11354 }
11355
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11356 {
11357 new_return(73);
11358 }
11359
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11360 {
11361 new_return(74);
11362 }
11363
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11364 {
11365 new_return(75);
11366 }
11367
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11368 {
11369 new_return(76);
11370 }
11371
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11372 {
11373 new_return(77);
11374 }
11375
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11376 {
11377 new_return(78);
11378 }
11379
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11380 {
11381 new_return(79);
11382 }
11383
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11384 {
11385 new_return(80);
11386 }
11387
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11388 {
11389 new_return(81);
11390 }
11391
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11392 {
11393 new_return(82);
11394 }
11395
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11396 {
11397 new_return(83);
11398 }
11399
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11400 {
11401 new_return(84);
11402 }
11403
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11404 {
11405 new_return(85);
11406 }
11407
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11408 {
11409
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11410 {
11411 new_return(86);
11412 }
11413 294912 }
11414
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11415 {
11416
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11417 {
11418 new_return(87);
11419 }
11420 294912 }
11421
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11422 {
11423 new_return(88);
11424 }
11425
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11426 {
11427
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11428 {
11429 new_return(89);
11430 }
11431 73728 }
11432
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11433 {
11434
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11435 {
11436 new_return(90);
11437 }
11438 18432 }
11439
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11440 {
11441 new_return(91);
11442 }
11443 //somehow forgot these in the older builds -Z
11444
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11445 {
11446 new_return(92);
11447 }
11448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11449 {
11450 new_return(93);
11451 }
11452
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11453 {
11454 new_return(94);
11455 }
11456
11457 //Enemy Editor InitD[] labels
11458
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11459 {
11460
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11461 {
11462
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11463 {
11464 new_return(95);
11465 }
11466 4792320 }
11467 73728 }
11468
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11469 new_return(99);
11470
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11471 new_return(100);
11472
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11473 new_return(101);
11474
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11475 new_return(102);
11476
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11477 new_return(103);
11478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11479 return ret;
11480 9216 }
11481
11482
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11483 {
11484 9 section_size=writesize;
11485 9 }
11486 18 }
11487
11488
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11489 {
11490 displayinfo("Error: writeguys()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
11491 }
11492
11493 9 new_return(0);
11494 9 }
11495
11496 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11497 {
11498 //these are here to bypass compiler warnings about unused arguments
11499 9 Header=Header;
11500
11501 9 dword section_id=ID_HEROSPRITES;
11502 9 dword section_version=V_HEROSPRITES;
11503 9 dword section_size=0;
11504
11505 //section id
11506
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11507 {
11508 new_return(1);
11509 }
11510
11511 //section version info
11512
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11513 {
11514 new_return(2);
11515 }
11516
11517
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
11518 {
11519 new_return(3);
11520 }
11521
11522
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11523 {
11524 18 fake_pack_writing=(writecycle==0);
11525
11526 //section size
11527
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11528 {
11529 new_return(4);
11530 }
11531
11532 18 writesize=0;
11533
11534 //finally... section data
11535
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11536 {
11537
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11538 {
11539 new_return(5);
11540 }
11541
11542
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11543 {
11544 new_return(5);
11545 }
11546
11547
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11548 {
11549 new_return(5);
11550 }
11551 72 }
11552
11553
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11554 {
11555
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11556 {
11557 new_return(6);
11558 }
11559
11560
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11561 {
11562 new_return(6);
11563 }
11564
11565
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11566 {
11567 new_return(6);
11568 }
11569 72 }
11570
11571
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11572 {
11573
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11574 {
11575 new_return(7);
11576 }
11577
11578
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11579 {
11580 new_return(7);
11581 }
11582
11583
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11584 {
11585 new_return(7);
11586 }
11587 72 }
11588
11589
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11590 {
11591
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11592 {
11593 new_return(8);
11594 }
11595
11596
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11597 {
11598 new_return(8);
11599 }
11600
11601
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11602 {
11603 new_return(8);
11604 }
11605 72 }
11606
11607
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11608 {
11609
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11610 {
11611 new_return(8);
11612 }
11613
11614
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11615 {
11616 new_return(8);
11617 }
11618
11619
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11620 {
11621 new_return(8);
11622 }
11623 72 }
11624
11625
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11626 {
11627
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11628 {
11629 new_return(9);
11630 }
11631
11632
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11633 {
11634 new_return(9);
11635 }
11636
11637
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11638 {
11639 new_return(9);
11640 }
11641 72 }
11642
11643
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11644 {
11645
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11646 {
11647 new_return(10);
11648 }
11649
11650
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11651 {
11652 new_return(10);
11653 }
11654
11655
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11656 {
11657 new_return(10);
11658 }
11659 72 }
11660
11661
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11662 {
11663 new_return(11);
11664 }
11665
11666
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11667 {
11668 new_return(11);
11669 }
11670
11671
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11672 {
11673 new_return(11);
11674 }
11675
11676
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11677 {
11678
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11679 {
11680
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11681 {
11682 new_return(12);
11683 }
11684
11685
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11686 {
11687 new_return(12);
11688 }
11689
11690
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11691 {
11692 new_return(12);
11693 }
11694 108 }
11695 36 }
11696
11697
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11698 {
11699
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11700 {
11701 new_return(13);
11702 }
11703
11704
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11705 {
11706 new_return(13);
11707 }
11708
11709
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11710 {
11711 new_return(13);
11712 }
11713 72 }
11714
11715
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11716 {
11717
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11718 {
11719 new_return(13);
11720 }
11721
11722
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11723 {
11724 new_return(13);
11725 }
11726
11727
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11728 {
11729 new_return(13);
11730 }
11731 72 }
11732
11733
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11734 {
11735 new_return(14);
11736 }
11737
11738 //{ V_HEROSPRITES >= 7
11739
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11740 {
11741
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11742 new_return(15);
11743
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11744 new_return(15);
11745
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11746 new_return(15);
11747 72 }
11748
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11749 {
11750
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11751 new_return(15);
11752
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11753 new_return(15);
11754
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11755 new_return(15);
11756 72 }
11757
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11758 {
11759
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11760 new_return(15);
11761
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11762 new_return(15);
11763
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11764 new_return(15);
11765 72 }
11766
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11767 {
11768
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11769 new_return(15);
11770
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11771 new_return(15);
11772
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11773 new_return(15);
11774 72 }
11775
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11776 {
11777
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11778 new_return(15);
11779
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11780 new_return(15);
11781
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11782 new_return(15);
11783 72 }
11784
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11785 {
11786
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11787 new_return(15);
11788
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11789 new_return(15);
11790
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11791 new_return(15);
11792 72 }
11793
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11794 {
11795
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11796 new_return(15);
11797
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11798 new_return(15);
11799
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11800 new_return(15);
11801 72 }
11802
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11803 {
11804
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11805 new_return(15);
11806
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11807 new_return(15);
11808
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11809 new_return(15);
11810 72 }
11811
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11812 {
11813
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11814 new_return(15);
11815
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11816 new_return(15);
11817
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11818 new_return(15);
11819
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11820 new_return(15);
11821 72 }
11822
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11823 {
11824
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11825 new_return(15);
11826
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11827 new_return(15);
11828
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11829 new_return(15);
11830 72 }
11831
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11832 {
11833
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11834 new_return(15);
11835
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11836 new_return(15);
11837
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11838 new_return(15);
11839 72 }
11840
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11841 {
11842
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11843 new_return(15);
11844
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11845 new_return(15);
11846
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11847 new_return(15);
11848 72 }
11849
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11850 {
11851
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11852 new_return(15);
11853
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11854 new_return(15);
11855
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11856 new_return(15);
11857 72 }
11858
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11859 {
11860
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11861 new_return(15);
11862
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11863 new_return(15);
11864
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11865 new_return(15);
11866 72 }
11867
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11868 {
11869
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11870 new_return(15);
11871
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11872 new_return(15);
11873
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11874 new_return(15);
11875 72 }
11876
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11877 {
11878
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11879 new_return(15);
11880
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11881 new_return(15);
11882
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11883 new_return(15);
11884 72 }
11885
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11886 {
11887
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11888 new_return(15);
11889
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11890 new_return(15);
11891
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11892 new_return(15);
11893 72 }
11894
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11895 {
11896
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11897 new_return(15);
11898
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11899 new_return(15);
11900
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11901 new_return(15);
11902 72 }
11903
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11904 {
11905
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11906 new_return(15);
11907
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11908 new_return(15);
11909
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11910 new_return(15);
11911 72 }
11912
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11913 {
11914
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11915 new_return(15);
11916
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11917 new_return(15);
11918
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11919 new_return(15);
11920 72 }
11921
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11922 {
11923
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11924 new_return(15);
11925
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11926 new_return(15);
11927
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11928 new_return(15);
11929 72 }
11930
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11931 {
11932
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11933 new_return(15);
11934
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11935 new_return(15);
11936
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11937 new_return(15);
11938 72 }
11939
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11940 {
11941
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11942 new_return(15);
11943
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11944 new_return(15);
11945
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11946 new_return(15);
11947 72 }
11948
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11949 {
11950
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11951 new_return(15);
11952
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11953 new_return(15);
11954
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11955 new_return(15);
11956 54 }
11957
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11958 {
11959
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
11960 new_return(16);
11961
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
11962 new_return(16);
11963
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
11964 new_return(16);
11965 72 }
11966
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11967 {
11968
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
11969 new_return(17);
11970
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
11971 new_return(17);
11972
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
11973 new_return(17);
11974 72 }
11975
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11976 {
11977
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
11978 new_return(17);
11979
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
11980 new_return(17);
11981
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
11982 new_return(17);
11983 72 }
11984
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11985 {
11986
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
11987 new_return(17);
11988
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
11989 new_return(17);
11990
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
11991 new_return(17);
11992 72 }
11993
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11994 {
11995
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
11996 new_return(18);
11997
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
11998 new_return(18);
11999
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12000 new_return(18);
12001 72 }
12002
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12003 {
12004
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12005 new_return(19);
12006 72 }
12007
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12008 {
12009
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12010 new_return(20);
12011
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12012 new_return(20);
12013
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12014 new_return(20);
12015 54 }
12016
12017
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12018 {
12019 new_return(21);
12020 }
12021
12022
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12023 {
12024 new_return(21);
12025 }
12026
12027
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12028 {
12029 new_return(21);
12030 }
12031
12032
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12033 {
12034
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12035 new_return(22);
12036
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12037 new_return(22);
12038
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12039 new_return(22);
12040 72 }
12041
12042
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12043 {
12044
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12045 {
12046 new_return(23);
12047 }
12048
12049
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12050 {
12051 new_return(23);
12052 }
12053
12054
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12055 {
12056 new_return(23);
12057 }
12058 72 }
12059
12060
12061
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12062 {
12063
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12064 new_return(15);
12065 2628 }
12066 //}
12067
12068
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12069 {
12070 9 section_size=writesize;
12071 9 }
12072 18 }
12073
12074 //More data will come here
12075
12076
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12077 {
12078 displayinfo("Error: writeherosprites()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12079 }
12080
12081 9 new_return(0);
12082 }
12083
12084 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12085 {
12086 9 dword section_id=ID_SUBSCREEN;
12087 9 dword section_version=V_SUBSCREEN;
12088 9 dword section_size=0;
12089
12090 //section id
12091
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12092 {
12093 new_return(1);
12094 }
12095
12096 //section version info
12097
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12098 {
12099 new_return(2);
12100 }
12101
12102
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12103 {
12104 new_return(3);
12105 }
12106
12107
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12108 {
12109 18 fake_pack_writing=(writecycle==0);
12110
12111 //section size
12112
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12113 {
12114 new_return(4);
12115 }
12116
12117 18 writesize=0;
12118
12119 18 byte sz = subscreens_active.size();
12120
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12121 new_return(5);
12122
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12123 {
12124 86 int32_t ret = subscreens_active[i].write(f);
12125 86 fake_pack_writing=(writecycle==0);
12126
12127
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12128 new_return(ret);
12129 86 }
12130
12131 18 sz = subscreens_passive.size();
12132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(sz,f))
12133 new_return(5);
12134
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12135 {
12136 64 int32_t ret = subscreens_passive[i].write(f);
12137 64 fake_pack_writing=(writecycle==0);
12138
12139
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12140 new_return(ret);
12141 64 }
12142
12143 18 sz = subscreens_overlay.size();
12144
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12145 new_return(5);
12146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12147 {
12148 int32_t ret = subscreens_overlay[i].write(f);
12149 fake_pack_writing=(writecycle==0);
12150
12151 if(ret!=0)
12152 new_return(ret);
12153 }
12154
12155 18 sz = subscreens_map.size();
12156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(sz,f))
12157 new_return(5);
12158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12159 {
12160 int32_t ret = subscreens_map[i].write(f);
12161 fake_pack_writing=(writecycle==0);
12162
12163 if(ret!=0)
12164 new_return(ret);
12165 }
12166
12167
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12168 {
12169 9 section_size=writesize;
12170 9 }
12171 18 }
12172
12173
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12174 {
12175 displayinfo("Error: writesubscreens()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12176 }
12177
12178 9 new_return(0);
12179 9 }
12180
12181 extern script_data *ffscripts[NUMSCRIPTFFC];
12182 extern script_data *itemscripts[NUMSCRIPTITEM];
12183 extern script_data *guyscripts[NUMSCRIPTGUYS];
12184 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12185 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12186 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12187 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12188 extern script_data *playerscripts[NUMSCRIPTHERO];
12189 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12190 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12191 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12192 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12193 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12194
12195 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12196 {
12197
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12198 3 return writeffscript_old(f, Header);
12199
12200 6 dword section_id = ID_FFSCRIPT;
12201 6 dword section_version = V_FFSCRIPT;
12202 6 dword section_size = 0;
12203 6 dword zasmmeta_version = METADATA_V;
12204 6 byte numscripts = 0;
12205 6 numscripts = numscripts; //to avoid unused variables warnings
12206
12207 //section id
12208
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12209 {
12210 new_return(1);
12211 }
12212
12213 //section version info
12214
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12215 {
12216 new_return(2);
12217 }
12218
12219
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12220 {
12221 new_return(3);
12222 }
12223
12224
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12225 {
12226 new_return(4);
12227 }
12228
12229
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12230 {
12231 12 fake_pack_writing=(writecycle==0);
12232
12233 //section size
12234
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12235 {
12236 new_return(5);
12237 }
12238
12239 12 writesize=0;
12240
12241 12 write_quest_zasm(f);
12242
12243
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12244 {
12245 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12246
12247
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12248 {
12249 new_return(ret);
12250 }
12251 6144 }
12252
12253
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12254 {
12255 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12256
12257
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12258 {
12259 new_return(ret);
12260 }
12261 3072 }
12262
12263
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12264 {
12265 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12266
12267
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12268 {
12269 new_return(ret);
12270 }
12271 3072 }
12272
12273
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12274
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12275 {
12276 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12277
12278
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12279 {
12280 new_return(ret);
12281 }
12282 3072 }
12283
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12284
12285
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12286 {
12287 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12288
12289
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12290 {
12291 new_return(ret);
12292 }
12293 3072 }
12294
12295
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12296 {
12297 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12298
12299
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12300 {
12301 new_return(ret);
12302 }
12303 96 }
12304
12305
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12306 {
12307 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12308
12309
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12310 {
12311 new_return(ret);
12312 }
12313 60 }
12314
12315
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12316 {
12317 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12318
12319
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12320 {
12321 new_return(ret);
12322 }
12323 3072 }
12324
12325
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12326 {
12327 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12328
12329
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12330 {
12331 new_return(ret);
12332 }
12333 3072 }
12334
12335
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12336 {
12337 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12338
12339
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12340 {
12341 new_return(ret);
12342 }
12343 3072 }
12344
12345
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12346 {
12347 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12348
12349
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12350 {
12351 new_return(ret);
12352 }
12353 3072 }
12354
12355
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12356 {
12357 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12358
12359
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12360 {
12361 new_return(ret);
12362 }
12363 6144 }
12364
12365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12366 {
12367 new_return(2000);
12368 }
12369
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12370 {
12371 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12372
12373
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12374 {
12375 new_return(ret);
12376 }
12377 6144 }
12378
12379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12380 {
12381 new_return(2001);
12382 }
12383
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12384 {
12385 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12386
12387
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12388 {
12389 new_return(ret);
12390 }
12391 3072 }
12392
12393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12394 {
12395 new_return(2001);
12396 }
12397
12398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12399 {
12400 new_return(2002);
12401 }
12402
12403 12 word numffcbindings=0;
12404
12405
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12406 {
12407
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12408 {
12409 158 numffcbindings++;
12410 158 }
12411 6132 }
12412
12413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12414 {
12415 new_return(2003);
12416 }
12417
12418
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12419 {
12420
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12421 {
12422
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12423 {
12424 new_return(2004);
12425 }
12426
12427
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12428 {
12429 new_return(2005);
12430 }
12431
12432
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12433 {
12434 new_return(2006);
12435 }
12436 158 }
12437 6132 }
12438
12439 12 word numglobalbindings=0;
12440
12441
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12442 {
12443
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12444 {
12445 22 numglobalbindings++;
12446 22 }
12447 96 }
12448
12449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12450 {
12451 new_return(2007);
12452 }
12453
12454
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12455 {
12456
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12457 {
12458
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12459 {
12460 new_return(2008);
12461 }
12462
12463
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12464 {
12465 new_return(2009);
12466 }
12467
12468
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12469 {
12470 new_return(2010);
12471 }
12472 22 }
12473 96 }
12474
12475 12 word numitembindings=0;
12476
12477
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12478 {
12479
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12480 {
12481 26 numitembindings++;
12482 26 }
12483 3060 }
12484
12485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12486 {
12487 new_return(2011);
12488 }
12489
12490
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12491 {
12492
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12493 {
12494
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12495 {
12496 new_return(2012);
12497 }
12498
12499
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12500 {
12501 new_return(2013);
12502 }
12503
12504
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12505 {
12506 new_return(2014);
12507 }
12508 26 }
12509 3060 }
12510
12511 //new script types
12512 //npc scripts
12513 12 word numnpcbindings=0;
12514
12515
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12516 {
12517
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12518 {
12519 numnpcbindings++;
12520 }
12521 3060 }
12522
12523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12524 {
12525 new_return(2015);
12526 }
12527
12528
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12529 {
12530
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12531 {
12532 if(!p_iputw(it->first,f))
12533 {
12534 new_return(2016);
12535 }
12536
12537 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12538 {
12539 new_return(2017);
12540 }
12541
12542 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12543 {
12544 new_return(2018);
12545 }
12546 }
12547 3060 }
12548
12549 //lweapon
12550
12551 12 word numlwpnbindings=0;
12552
12553
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12554 {
12555
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12556 {
12557 2 numlwpnbindings++;
12558 2 }
12559 3060 }
12560
12561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12562 {
12563 new_return(2019);
12564 }
12565
12566
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12567 {
12568
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12569 {
12570
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12571 {
12572 new_return(2020);
12573 }
12574
12575
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12576 {
12577 new_return(2021);
12578 }
12579
12580
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12581 {
12582 new_return(2022);
12583 }
12584 2 }
12585 3060 }
12586
12587 //////
12588
12589 //eweapon
12590
12591
12592 12 word numewpnbindings=0;
12593
12594
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12595 {
12596
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12597 {
12598 numewpnbindings++;
12599 }
12600 3060 }
12601
12602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12603 {
12604 new_return(2023);
12605 }
12606
12607
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12608 {
12609
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12610 {
12611 if(!p_iputw(it->first,f))
12612 {
12613 new_return(2024);
12614 }
12615
12616 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12617 {
12618 new_return(2025);
12619 }
12620
12621 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12622 {
12623 new_return(2026);
12624 }
12625 }
12626 3060 }
12627
12628 //player scripts
12629 12 word numherobindings=0;
12630
12631
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12632 {
12633
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12634 {
12635 numherobindings++;
12636 }
12637 48 }
12638
12639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12640 {
12641 new_return(2027);
12642 }
12643
12644
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12645 {
12646
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12647 {
12648 if(!p_iputw(it->first,f))
12649 {
12650 new_return(2028);
12651 }
12652
12653 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12654 {
12655 new_return(2029);
12656 }
12657
12658 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12659 {
12660 new_return(2030);
12661 }
12662 }
12663 48 }
12664
12665 //dmap scripts
12666 12 word numdmapbindings=0;
12667
12668
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12669 {
12670
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12671 {
12672 10 numdmapbindings++;
12673 10 }
12674 3060 }
12675
12676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12677 {
12678 new_return(2031);
12679 }
12680
12681
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12682 {
12683
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12684 {
12685
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12686 {
12687 new_return(2032);
12688 }
12689
12690
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12691 {
12692 new_return(2033);
12693 }
12694
12695
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12696 {
12697 new_return(2034);
12698 }
12699 10 }
12700 3060 }
12701
12702 //screen scripts
12703 12 word numscreenbindings=0;
12704
12705
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12706 {
12707
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12708 {
12709 4 numscreenbindings++;
12710 4 }
12711 3060 }
12712
12713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12714 {
12715 new_return(2035);
12716 }
12717
12718
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12719 {
12720
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12721 {
12722
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12723 {
12724 new_return(2036);
12725 }
12726
12727
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12728 {
12729 new_return(2037);
12730 }
12731
12732
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12733 {
12734 new_return(2038);
12735 }
12736 4 }
12737 3060 }
12738 //item sprite scripts
12739 12 word numitemspritebindings=0;
12740
12741
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12742 {
12743
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12744 {
12745 numitemspritebindings++;
12746 }
12747 3060 }
12748
12749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12750 {
12751 new_return(2039);
12752 }
12753
12754
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12755 {
12756
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12757 {
12758 if(!p_iputw(it->first,f))
12759 {
12760 new_return(2040);
12761 }
12762
12763 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12764 {
12765 new_return(2041);
12766 }
12767
12768 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12769 {
12770 new_return(2042);
12771 }
12772 }
12773 3060 }
12774
12775 //combo scripts
12776 12 word numcombobindings=0;
12777
12778
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12779 {
12780
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12781 {
12782 numcombobindings++;
12783 }
12784 6132 }
12785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12786 {
12787 new_return(2043);
12788 }
12789
12790
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12791 {
12792
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12793 {
12794 if(!p_iputw(it->first,f))
12795 {
12796 new_return(2044);
12797 }
12798
12799 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12800 {
12801 new_return(2045);
12802 }
12803
12804 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12805 {
12806 new_return(2046);
12807 }
12808 }
12809 6132 }
12810 //subscreen scripts
12811 12 word numgenericbindings=0;
12812
12813
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12814 {
12815
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 44 times.
6132 if(it->second.scriptname != "")
12816 {
12817 44 numgenericbindings++;
12818 44 }
12819 6132 }
12820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12821 {
12822 new_return(2043);
12823 }
12824
12825
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12826 {
12827
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 44 times.
6132 if(it->second.scriptname != "")
12828 {
12829
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!p_iputw(it->first,f))
12830 {
12831 new_return(2044);
12832 }
12833
12834
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12835 {
12836 new_return(2045);
12837 }
12838
12839
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12840 {
12841 new_return(2046);
12842 }
12843 44 }
12844 6132 }
12845
12846 //generic scripts
12847 12 word numsubscreenbindings=0;
12848
12849
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12850 {
12851
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12852 {
12853 numsubscreenbindings++;
12854 }
12855 3060 }
12856
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12857 {
12858 new_return(2047);
12859 }
12860
12861
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12862 {
12863
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12864 {
12865 if(!p_iputw(it->first,f))
12866 {
12867 new_return(2048);
12868 }
12869
12870 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12871 {
12872 new_return(2049);
12873 }
12874
12875 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12876 {
12877 new_return(2050);
12878 }
12879 }
12880 3060 }
12881
12882
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12883 {
12884 6 section_size=writesize;
12885 6 }
12886 12 }
12887
12888
12889
12890
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12891 {
12892 displayinfo("Error: writeffscript()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12893 }
12894
12895 6 new_return(0);
12896 //return 0; //this is just here to stomp the compiler from whining.
12897 //the irony is that it causes an "unreachable code" warning.
12898 9 }
12899
12900 12 int32_t write_quest_zasm(PACKFILE *f)
12901 {
12902 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12903
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12904 {
12905 if(!p_iputl(0,f))
12906 new_return(1);
12907
12908 return 0;
12909 }
12910
12911 12 auto& zasm = zasm_scripts[0]->zasm;
12912 12 size_t num_commands = zasm.size();
12913
12914
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12915 new_return(1);
12916
12917
2/2
✓ Branch 0 taken 374364 times.
✓ Branch 1 taken 12 times.
374376 for(int32_t j=0; j<num_commands; j++)
12918 {
12919 374364 auto& zas = zasm[j];
12920
12921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 374364 times.
374364 if(zas.command==0xFFFF)
12922 continue;
12923 else
12924 {
12925
1/2
✓ Branch 0 taken 374364 times.
✗ Branch 1 not taken.
374364 if(!p_iputw(zas.command,f))
12926 new_return(2);
12927
12928
1/2
✓ Branch 0 taken 374364 times.
✗ Branch 1 not taken.
374364 if(!p_iputl(zas.arg1,f))
12929 new_return(3);
12930
12931
1/2
✓ Branch 0 taken 374364 times.
✗ Branch 1 not taken.
374364 if(!p_iputl(zas.arg2,f))
12932 new_return(4);
12933
12934
1/2
✓ Branch 0 taken 374364 times.
✗ Branch 1 not taken.
374364 if(!p_iputl(zas.arg3,f))
12935 new_return(5);
12936
12937 374364 uint32_t sz = 0;
12938
2/2
✓ Branch 0 taken 373304 times.
✓ Branch 1 taken 1060 times.
374364 if(zas.strptr)
12939 1060 sz = zas.strptr->size();
12940
1/2
✓ Branch 0 taken 374364 times.
✗ Branch 1 not taken.
374364 if(!p_iputl(sz,f))
12941 new_return(6);
12942
2/2
✓ Branch 0 taken 373320 times.
✓ Branch 1 taken 1044 times.
374364 if(sz)
12943 {
12944 1044 auto& str = *zas.strptr;
12945
2/2
✓ Branch 0 taken 22550 times.
✓ Branch 1 taken 1044 times.
23594 for(size_t q = 0; q < sz; ++q)
12946 {
12947
1/2
✓ Branch 0 taken 22550 times.
✗ Branch 1 not taken.
22550 if(!p_putc(str[q],f))
12948 new_return(7);
12949 22550 }
12950 1044 }
12951 374364 sz = 0;
12952
2/2
✓ Branch 0 taken 374146 times.
✓ Branch 1 taken 218 times.
374364 if(zas.vecptr)
12953 218 sz = zas.vecptr->size();
12954
1/2
✓ Branch 0 taken 374364 times.
✗ Branch 1 not taken.
374364 if(!p_iputl(sz,f))
12955 new_return(8);
12956
2/2
✓ Branch 0 taken 374146 times.
✓ Branch 1 taken 218 times.
374364 if(sz) //vector found
12957 {
12958 218 auto& vec = *zas.vecptr;
12959
2/2
✓ Branch 0 taken 1320 times.
✓ Branch 1 taken 218 times.
1538 for(size_t q = 0; q < sz; ++q)
12960 {
12961
1/2
✓ Branch 0 taken 1320 times.
✗ Branch 1 not taken.
1320 if(!p_iputl(vec[q],f))
12962 new_return(9);
12963 1320 }
12964 218 }
12965 }
12966 374364 }
12967 12 return 0;
12968 12 }
12969
12970 23370 int32_t write_one_ffscript_meta(PACKFILE *f, zasm_meta const& tmeta)
12971 {
12972
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.zasm_v,f))
12973 new_return(1);
12974
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.meta_v,f))
12975 new_return(2);
12976
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.ffscript_v,f))
12977 new_return(3);
12978
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_putc((int)tmeta.script_type,f))
12979 new_return(4);
12980
12981
2/2
✓ Branch 0 taken 186960 times.
✓ Branch 1 taken 23370 times.
210330 for(int32_t q = 0; q < 8; ++q)
12982 {
12983
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putcstr(tmeta.run_idens[q],f))
12984 new_return(5);
12985 186960 }
12986
12987
2/2
✓ Branch 0 taken 186960 times.
✓ Branch 1 taken 23370 times.
210330 for(int32_t q = 0; q < 8; ++q)
12988
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putc(tmeta.run_types[q],f))
12989 new_return(6);
12990
12991
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_putc(tmeta.flags,f))
12992 new_return(7);
12993
12994
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.compiler_v1,f))
12995 new_return(8);
12996
12997
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.compiler_v2,f))
12998 new_return(9);
12999
13000
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.compiler_v3,f))
13001 new_return(10);
13002
13003
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.compiler_v4,f))
13004 new_return(11);
13005
13006
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_putcstr(tmeta.script_name,f))
13007 new_return(12);
13008
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_putcstr(tmeta.author,f))
13009 new_return(13);
13010
13011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23370 times.
23370 if (!p_iputw(NUM_ZMETA_ATTRIBUTES, f))
13012 new_return(27);
13013
2/2
✓ Branch 0 taken 560880 times.
✓ Branch 1 taken 23370 times.
584250 for(auto q = 0; q < NUM_ZMETA_ATTRIBUTES; ++q)
13014 {
13015
1/2
✓ Branch 0 taken 560880 times.
✗ Branch 1 not taken.
560880 if(!p_putcstr(tmeta.attributes[q],f))
13016 new_return(28);
13017
1/2
✓ Branch 0 taken 560880 times.
✗ Branch 1 not taken.
560880 if(!p_putwstr(tmeta.attributes_help[q],f))
13018 new_return(29);
13019 560880 }
13020
2/2
✓ Branch 0 taken 373920 times.
✓ Branch 1 taken 23370 times.
397290 for(auto q = 0; q < 16; ++q)
13021 {
13022
1/2
✓ Branch 0 taken 373920 times.
✗ Branch 1 not taken.
373920 if(!p_putcstr(tmeta.usrflags[q],f))
13023 new_return(20);
13024
1/2
✓ Branch 0 taken 373920 times.
✗ Branch 1 not taken.
373920 if(!p_putwstr(tmeta.usrflags_help[q],f))
13025 new_return(21);
13026 373920 }
13027
2/2
✓ Branch 0 taken 186960 times.
✓ Branch 1 taken 23370 times.
210330 for(auto q = 0; q < 8; ++q)
13028 {
13029
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putcstr(tmeta.initd[q],f))
13030 new_return(22);
13031
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putwstr(tmeta.initd_help[q],f))
13032 new_return(23);
13033 186960 }
13034
2/2
✓ Branch 0 taken 186960 times.
✓ Branch 1 taken 23370 times.
210330 for(auto q = 0; q < 8; ++q)
13035 {
13036
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putc(tmeta.initd_type[q],f))
13037 new_return(24);
13038 186960 }
13039
13040 23370 return 0;
13041 }
13042
13043 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13044 {
13045
2/2
✓ Branch 0 taken 45984 times.
✓ Branch 1 taken 252 times.
46236 if (!script->valid())
13046 {
13047
1/2
✓ Branch 0 taken 45984 times.
✗ Branch 1 not taken.
45984 if (!p_putc(0, f))
13048 new_return(-1);
13049 45984 return 0;
13050 }
13051
13052
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if (!p_putc(1, f))
13053 new_return(-1);
13054
13055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if (auto ret = write_one_ffscript_meta(f, script->meta))
13056 return ret;
13057
13058
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputl(script->pc, f))
13059 new_return(25);
13060
13061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!p_iputl(script->end_pc, f))
13062 new_return(26);
13063
13064 252 return 0;
13065 46236 }
13066
13067 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13068 {
13069 3 dword section_id = ID_FFSCRIPT;
13070 3 dword section_version = 26;
13071 3 dword section_cversion = 1;
13072 3 dword section_size = 0;
13073 3 dword zasmmeta_version = METADATA_V;
13074 3 byte numscripts = 0;
13075 3 numscripts = numscripts; //to avoid unused variables warnings
13076
13077 //section id
13078
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13079 {
13080 new_return(1);
13081 }
13082
13083 //section version info
13084
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13085 {
13086 new_return(2);
13087 }
13088
13089
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13090 {
13091 new_return(3);
13092 }
13093
13094
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13095 {
13096 new_return(4);
13097 }
13098
13099
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13100 {
13101 6 fake_pack_writing=(writecycle==0);
13102
13103 //section size
13104
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13105 {
13106 new_return(5);
13107 }
13108
13109 6 writesize=0;
13110
13111
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13112 {
13113 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13114 3072 fake_pack_writing=(writecycle==0);
13115
13116
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13117 {
13118 new_return(ret);
13119 }
13120 3072 }
13121
13122
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13123 {
13124 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13125 1536 fake_pack_writing=(writecycle==0);
13126
13127
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13128 {
13129 new_return(ret);
13130 }
13131 1536 }
13132
13133
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13134 {
13135 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13136 1536 fake_pack_writing=(writecycle==0);
13137
13138
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13139 {
13140 new_return(ret);
13141 }
13142 1536 }
13143
13144
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13145
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13146 {
13147 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13148 1536 fake_pack_writing=(writecycle==0);
13149
13150
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13151 {
13152 new_return(ret);
13153 }
13154 1536 }
13155
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13156
13157
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13158 {
13159 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13160 1536 fake_pack_writing=(writecycle==0);
13161
13162
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13163 {
13164 new_return(ret);
13165 }
13166 1536 }
13167
13168
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13169 {
13170 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13171 48 fake_pack_writing=(writecycle==0);
13172
13173
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13174 {
13175 new_return(ret);
13176 }
13177 48 }
13178
13179
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13180 {
13181 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13182 30 fake_pack_writing=(writecycle==0);
13183
13184
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13185 {
13186 new_return(ret);
13187 }
13188 30 }
13189
13190
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13191 {
13192 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13193 1536 fake_pack_writing=(writecycle==0);
13194
13195
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13196 {
13197 new_return(ret);
13198 }
13199 1536 }
13200
13201
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13202 {
13203 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13204 1536 fake_pack_writing=(writecycle==0);
13205
13206
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13207 {
13208 new_return(ret);
13209 }
13210 1536 }
13211
13212
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13213 {
13214 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13215 1536 fake_pack_writing=(writecycle==0);
13216
13217
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13218 {
13219 new_return(ret);
13220 }
13221 1536 }
13222
13223
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13224 {
13225 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13226 1536 fake_pack_writing=(writecycle==0);
13227
13228
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13229 {
13230 new_return(ret);
13231 }
13232 1536 }
13233
13234
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13235 {
13236 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13237 3072 fake_pack_writing=(writecycle==0);
13238
13239
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13240 {
13241 new_return(ret);
13242 }
13243 3072 }
13244
13245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13246 {
13247 new_return(2000);
13248 }
13249
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13250 {
13251 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13252 3072 fake_pack_writing=(writecycle==0);
13253
13254
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13255 {
13256 new_return(ret);
13257 }
13258 3072 }
13259
13260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13261 {
13262 new_return(2001);
13263 }
13264
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13265 {
13266 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13267 1536 fake_pack_writing=(writecycle==0);
13268
13269
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13270 {
13271 new_return(ret);
13272 }
13273 1536 }
13274
13275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13276 {
13277 new_return(2001);
13278 }
13279
13280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13281 {
13282 new_return(2002);
13283 }
13284
13285 6 word numffcbindings=0;
13286
13287
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13288 {
13289
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13290 {
13291 206 numffcbindings++;
13292 206 }
13293 3066 }
13294
13295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13296 {
13297 new_return(2003);
13298 }
13299
13300
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13301 {
13302
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13303 {
13304
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13305 {
13306 new_return(2004);
13307 }
13308
13309
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13310 {
13311 new_return(2005);
13312 }
13313
13314
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13315 {
13316 new_return(2006);
13317 }
13318 206 }
13319 3066 }
13320
13321 6 word numglobalbindings=0;
13322
13323
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13324 {
13325
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13326 {
13327 18 numglobalbindings++;
13328 18 }
13329 48 }
13330
13331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13332 {
13333 new_return(2007);
13334 }
13335
13336
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13337 {
13338
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13339 {
13340
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13341 {
13342 new_return(2008);
13343 }
13344
13345
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13346 {
13347 new_return(2009);
13348 }
13349
13350
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13351 {
13352 new_return(2010);
13353 }
13354 18 }
13355 48 }
13356
13357 6 word numitembindings=0;
13358
13359
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13360 {
13361
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13362 {
13363 18 numitembindings++;
13364 18 }
13365 1530 }
13366
13367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13368 {
13369 new_return(2011);
13370 }
13371
13372
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13373 {
13374
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13375 {
13376
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13377 {
13378 new_return(2012);
13379 }
13380
13381
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13382 {
13383 new_return(2013);
13384 }
13385
13386
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13387 {
13388 new_return(2014);
13389 }
13390 18 }
13391 1530 }
13392
13393 //new script types
13394 //npc scripts
13395 6 word numnpcbindings=0;
13396
13397
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13398 {
13399
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13400 {
13401 numnpcbindings++;
13402 }
13403 1530 }
13404
13405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13406 {
13407 new_return(2015);
13408 }
13409
13410
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13411 {
13412
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13413 {
13414 if(!p_iputw(it->first,f))
13415 {
13416 new_return(2016);
13417 }
13418
13419 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13420 {
13421 new_return(2017);
13422 }
13423
13424 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13425 {
13426 new_return(2018);
13427 }
13428 }
13429 1530 }
13430
13431 //lweapon
13432
13433 6 word numlwpnbindings=0;
13434
13435
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13436 {
13437
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13438 {
13439 numlwpnbindings++;
13440 }
13441 1530 }
13442
13443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13444 {
13445 new_return(2019);
13446 }
13447
13448
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13449 {
13450
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13451 {
13452 if(!p_iputw(it->first,f))
13453 {
13454 new_return(2020);
13455 }
13456
13457 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13458 {
13459 new_return(2021);
13460 }
13461
13462 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13463 {
13464 new_return(2022);
13465 }
13466 }
13467 1530 }
13468
13469 //////
13470
13471 //eweapon
13472
13473
13474 6 word numewpnbindings=0;
13475
13476
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13477 {
13478
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13479 {
13480 numewpnbindings++;
13481 }
13482 1530 }
13483
13484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13485 {
13486 new_return(2023);
13487 }
13488
13489
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13490 {
13491
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13492 {
13493 if(!p_iputw(it->first,f))
13494 {
13495 new_return(2024);
13496 }
13497
13498 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13499 {
13500 new_return(2025);
13501 }
13502
13503 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13504 {
13505 new_return(2026);
13506 }
13507 }
13508 1530 }
13509
13510 //player scripts
13511 6 word numherobindings=0;
13512
13513
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13514 {
13515
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13516 {
13517 2 numherobindings++;
13518 2 }
13519 24 }
13520
13521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13522 {
13523 new_return(2027);
13524 }
13525
13526
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13527 {
13528
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13529 {
13530
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13531 {
13532 new_return(2028);
13533 }
13534
13535
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13536 {
13537 new_return(2029);
13538 }
13539
13540
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13541 {
13542 new_return(2030);
13543 }
13544 2 }
13545 24 }
13546
13547 //dmap scripts
13548 6 word numdmapbindings=0;
13549
13550
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13551 {
13552
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13553 {
13554 numdmapbindings++;
13555 }
13556 1530 }
13557
13558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13559 {
13560 new_return(2031);
13561 }
13562
13563
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13564 {
13565
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13566 {
13567 if(!p_iputw(it->first,f))
13568 {
13569 new_return(2032);
13570 }
13571
13572 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13573 {
13574 new_return(2033);
13575 }
13576
13577 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13578 {
13579 new_return(2034);
13580 }
13581 }
13582 1530 }
13583
13584 //screen scripts
13585 6 word numscreenbindings=0;
13586
13587
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13588 {
13589
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13590 {
13591 14 numscreenbindings++;
13592 14 }
13593 1530 }
13594
13595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13596 {
13597 new_return(2035);
13598 }
13599
13600
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13601 {
13602
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13603 {
13604
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13605 {
13606 new_return(2036);
13607 }
13608
13609
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13610 {
13611 new_return(2037);
13612 }
13613
13614
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13615 {
13616 new_return(2038);
13617 }
13618 14 }
13619 1530 }
13620 //item sprite scripts
13621 6 word numitemspritebindings=0;
13622
13623
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13624 {
13625
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13626 {
13627 numitemspritebindings++;
13628 }
13629 1530 }
13630
13631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13632 {
13633 new_return(2039);
13634 }
13635
13636
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13637 {
13638
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13639 {
13640 if(!p_iputw(it->first,f))
13641 {
13642 new_return(2040);
13643 }
13644
13645 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13646 {
13647 new_return(2041);
13648 }
13649
13650 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13651 {
13652 new_return(2042);
13653 }
13654 }
13655 1530 }
13656
13657 //combo scripts
13658 6 word numcombobindings=0;
13659
13660
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13661 {
13662
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13663 {
13664 numcombobindings++;
13665 }
13666 3066 }
13667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13668 {
13669 new_return(2043);
13670 }
13671
13672
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13673 {
13674
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13675 {
13676 if(!p_iputw(it->first,f))
13677 {
13678 new_return(2044);
13679 }
13680
13681 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13682 {
13683 new_return(2045);
13684 }
13685
13686 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13687 {
13688 new_return(2046);
13689 }
13690 }
13691 3066 }
13692 //subscreen scripts
13693 6 word numgenericbindings=0;
13694
13695
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13696 {
13697
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13698 {
13699 numgenericbindings++;
13700 }
13701 3066 }
13702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13703 {
13704 new_return(2043);
13705 }
13706
13707
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13708 {
13709
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13710 {
13711 if(!p_iputw(it->first,f))
13712 {
13713 new_return(2044);
13714 }
13715
13716 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13717 {
13718 new_return(2045);
13719 }
13720
13721 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13722 {
13723 new_return(2046);
13724 }
13725 }
13726 3066 }
13727
13728 //generic scripts
13729 6 word numsubscreenbindings=0;
13730
13731
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13732 {
13733
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13734 {
13735 numsubscreenbindings++;
13736 }
13737 1530 }
13738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13739 {
13740 new_return(2047);
13741 }
13742
13743
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13744 {
13745
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13746 {
13747 if(!p_iputw(it->first,f))
13748 {
13749 new_return(2048);
13750 }
13751
13752 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13753 {
13754 new_return(2049);
13755 }
13756
13757 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13758 {
13759 new_return(2050);
13760 }
13761 }
13762 1530 }
13763
13764
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13765 {
13766 3 section_size=writesize;
13767 3 }
13768 6 }
13769
13770
13771
13772
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13773 {
13774 displayinfo("Error: writeffscript()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
13775 }
13776
13777 3 new_return(0);
13778 //return 0; //this is just here to stomp the compiler from whining.
13779 //the irony is that it causes an "unreachable code" warning.
13780 3 }
13781
13782 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13783 {
13784
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13785
13786
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13787 {
13788 new_return(6);
13789 }
13790
13791 //Metadata
13792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if (auto ret = write_one_ffscript_meta(f, script->meta))
13793 return ret;
13794
13795
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13796 {
13797 2056888 auto& zas = script->zasm_script->zasm[j];
13798
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13799 {
13800 new_return(20);
13801 }
13802
13803
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13804 {
13805 11830 break;
13806 }
13807 else
13808 {
13809
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13810 {
13811 new_return(21);
13812 }
13813
13814
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13815 {
13816 new_return(22);
13817 }
13818
13819
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13820 {
13821 new_return(23);
13822 }
13823
13824 2045058 uint32_t sz = 0;
13825
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(zas.strptr)
13826 2340 sz = zas.strptr->size();
13827
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13828 {
13829 new_return(23);
13830 }
13831
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13832 {
13833 2340 auto& str = *zas.strptr;
13834
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13835 {
13836
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13837 {
13838 new_return(24);
13839 }
13840 214720 }
13841 2340 }
13842 2045058 sz = 0;
13843
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13844 22 sz = zas.vecptr->size();
13845
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13846 {
13847 new_return(25);
13848 }
13849
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13850 {
13851 22 auto& vec = *zas.vecptr;
13852
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13853 {
13854
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13855 {
13856 new_return(26);
13857 }
13858 352 }
13859 22 }
13860 }
13861 2045058 }
13862
13863 23118 new_return(0);
13864 23118 }
13865
13866 extern SAMPLE customsfxdata[WAV_COUNT];
13867 extern uint8_t customsfxflag[WAV_COUNT>>3];
13868
13869 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13870 {
13871 //these are here to bypass compiler warnings about unused arguments
13872 9 Header=Header;
13873
13874 9 dword section_id=ID_SFX;
13875 9 dword section_version=V_SFX;
13876 9 dword section_size=0;
13877
13878 //section id
13879
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
13880 {
13881 new_return(1);
13882 }
13883
13884 //section version info
13885
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
13886 {
13887 new_return(2);
13888 }
13889
13890
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
13891 {
13892 new_return(3);
13893 }
13894
13895
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13896 {
13897 18 fake_pack_writing=(writecycle==0);
13898
13899 //section size
13900
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
13901 {
13902 new_return(4);
13903 }
13904
13905 18 writesize=0;
13906
13907
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13908 {
13909
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
13910 {
13911 new_return(5);
13912 }
13913 576 }
13914
13915
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
13916 {
13917
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
13918 3330 continue;
13919
13920
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
13921 {
13922 new_return(5);
13923 }
13924 1260 }
13925
13926
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
13927 {
13928
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
13929 3330 continue;
13930
13931
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
13932 {
13933 new_return(5);
13934 }
13935
13936
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
13937 {
13938 new_return(6);
13939 }
13940
13941
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
13942 {
13943 new_return(7);
13944 }
13945
13946
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
13947 {
13948 new_return(8);
13949 }
13950
13951
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
13952 {
13953 new_return(9);
13954 }
13955
13956
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
13957 {
13958 new_return(10);
13959 }
13960
13961
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
13962 {
13963 new_return(11);
13964 }
13965
13966
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
13967 {
13968 new_return(12);
13969 }
13970
13971 //de-endianfy the data
13972 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13973
13974
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 28596352 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
13975 {
13976
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13977 {
13978 new_return(13);
13979 }
13980 28596352 }
13981 1260 }
13982
13983
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
13984 {
13985 9 section_size=writesize;
13986 9 }
13987 18 }
13988
13989
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
13990 {
13991 displayinfo("Error: writesfx()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
13992 }
13993
13994 9 new_return(0);
13995 }
13996
13997 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13998 {
13999 9 dword section_id=ID_INITDATA;
14000 9 dword section_version=V_INITDATA;
14001 9 dword section_size = 0;
14002
14003 9 zinit.last_map=Map.getCurrMap();
14004 9 zinit.last_screen=Map.getCurrScr();
14005 9 zinit.normalize();
14006
14007 //section id
14008
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14009 {
14010 new_return(1);
14011 }
14012
14013 //section version info
14014
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14015 {
14016 new_return(2);
14017 }
14018
14019
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14020 {
14021 new_return(3);
14022 }
14023
14024 //TODO
14025
14026
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14027 {
14028 18 fake_pack_writing=(writecycle==0);
14029
14030 //section size
14031
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14032 new_return(4);
14033
14034 18 writesize=0;
14035
14036
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14037
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14038 new_return(5);
14039
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14040 {
14041
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14042 new_return(6);
14043 9216 }
14044
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14045 new_return(10);
14046
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14047 new_return(11);
14048
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14049
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14050 new_return(12);
14051
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14052
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14053 new_return(13);
14054
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14055 new_return(14);
14056
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14057 new_return(15);
14058
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14059 new_return(16);
14060
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14061 new_return(17);
14062
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14063 new_return(18);
14064
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14065 new_return(19);
14066
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14067 new_return(20);
14068
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14069 new_return(21);
14070
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14071 new_return(22);
14072
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14073 new_return(23);
14074
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14075 new_return(24);
14076
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14077 new_return(25);
14078
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14079 new_return(26);
14080
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14081 new_return(27);
14082
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14083 new_return(28);
14084
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14085 new_return(29);
14086
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14087 new_return(30);
14088
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14089 new_return(31);
14090
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14091 new_return(32);
14092
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14093 new_return(33);
14094
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14095 new_return(34);
14096
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14097 new_return(35);
14098
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14099 new_return(36);
14100
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14101 new_return(37);
14102
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14103 new_return(38);
14104
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14105 new_return(39);
14106
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14107 new_return(40);
14108
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14109 new_return(41);
14110
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14111 new_return(42);
14112
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14113 new_return(43);
14114
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14115 new_return(44);
14116
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14117 new_return(45);
14118
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14119 new_return(46);
14120
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14121 new_return(47);
14122
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14123 new_return(48);
14124
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14125 new_return(49);
14126
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14127 new_return(50);
14128
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14129 new_return(51);
14130
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14131 new_return(52);
14132
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14133 new_return(53);
14134
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14135 new_return(54);
14136
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14137 new_return(55);
14138
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14139 new_return(56);
14140
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14141 new_return(57);
14142
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14143 new_return(58);
14144
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14145 new_return(59);
14146
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14147 new_return(60);
14148
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14149 new_return(61);
14150
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14151 new_return(62);
14152
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14153 new_return(63);
14154
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14155 new_return(64);
14156
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14157 new_return(65);
14158
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14159 new_return(66);
14160
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14161 new_return(67);
14162
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14163 new_return(68);
14164
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14165 new_return(69);
14166
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14167 new_return(70);
14168
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14169 new_return(71);
14170
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14171 new_return(72);
14172
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14173 new_return(73);
14174
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14175 new_return(74);
14176
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14177 new_return(75);
14178
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14179
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14180 new_return(76);
14181
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14182 new_return(77);
14183
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14184 new_return(78);
14185
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14186 new_return(79);
14187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14188 new_return(80);
14189
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14190 new_return(81);
14191
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14192
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14193 new_return(82);
14194
14195
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14196 {
14197 9 section_size=writesize;
14198 9 }
14199 18 }
14200
14201
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14202 {
14203 displayinfo("Error: writeinitdata()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14204 }
14205
14206 9 new_return(0);
14207 }
14208
14209 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14210 {
14211 //these are here to bypass compiler warnings about unused arguments
14212 9 Header=Header;
14213
14214 9 dword section_id=ID_ITEMDROPSETS;
14215 9 dword section_version=V_ITEMDROPSETS;
14216 // dword section_size=0;
14217 9 dword section_size = 0;
14218 9 word num_item_drop_sets=count_item_drop_sets();
14219
14220 //section id
14221
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14222 {
14223 new_return(1);
14224 }
14225
14226 //section version info
14227
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14228 {
14229 new_return(2);
14230 }
14231
14232
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14233 {
14234 new_return(3);
14235 }
14236
14237
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14238 {
14239 18 fake_pack_writing=(writecycle==0);
14240
14241 //section size
14242
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14243 {
14244 new_return(4);
14245 }
14246
14247 18 writesize=0;
14248
14249 //finally... section data
14250
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14251 {
14252 new_return(5);
14253 }
14254
14255
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14256 {
14257
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14258 {
14259 new_return(6);
14260 }
14261
14262
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14263 {
14264
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14265 {
14266 new_return(7);
14267 }
14268 2360 }
14269
14270
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 2596 times.
2832 for(int32_t j=0; j<11; ++j)
14271 {
14272
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14273 {
14274 new_return(8);
14275 }
14276 2596 }
14277 236 }
14278
14279
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14280 {
14281 9 section_size=writesize;
14282 9 }
14283 18 }
14284
14285
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14286 {
14287 displayinfo("Error: writeitemdropsets()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14288 }
14289
14290 9 new_return(0);
14291 }
14292
14293 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14294 {
14295 9 dword section_id=ID_FAVORITES;
14296 9 dword section_version=V_FAVORITES;
14297 9 dword section_size = 0;
14298
14299 //section id
14300
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14301 {
14302 new_return(1);
14303 }
14304
14305 //section version info
14306
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14307 {
14308 new_return(2);
14309 }
14310
14311
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14312 {
14313 new_return(3);
14314 }
14315
14316
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14317 {
14318 18 fake_pack_writing=(writecycle==0);
14319
14320 //section size
14321
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14322 new_return(4);
14323
14324 18 writesize=0;
14325
14326
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14327 new_return(16);
14328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14329 new_return(17);
14330
14331 18 word favcmb_cnt = 0;
14332
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14333
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14334 {
14335 14 favcmb_cnt = q+1;
14336 14 break;
14337 }
14338
14339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14340 new_return(5);
14341
14342
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14343 {
14344
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14345 new_return(6);
14346
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14347 new_return(7);
14348 460 }
14349
14350
14351 18 word max_combo_cols = MAX_COMBO_COLS;
14352
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14353 new_return(9);
14354
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14355 {
14356
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14357 new_return(10);
14358
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14359 new_return(11);
14360
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14361 new_return(12);
14362 72 }
14363 18 word max_mappages = MAX_MAPPAGE_BTNS;
14364
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14365 new_return(13);
14366
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14367 {
14368
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14369 new_return(14);
14370
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14371 new_return(15);
14372 162 }
14373
14374
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14375 {
14376 9 section_size=writesize;
14377 9 }
14378 18 }
14379
14380
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14381 {
14382 displayinfo("Error: writefavorites()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14383 }
14384
14385 9 new_return(0);
14386 }
14387
14388 9 int32_t write_adv_music(PACKFILE *f, zquestheader*)
14389 {
14390 9 dword section_id = ID_ADVMUSIC;
14391 9 dword section_version = V_ADVMUSIC;
14392 9 dword section_size = 0;
14393
14394 //section id
14395
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14396 new_return(1);
14397 //section version info
14398
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14399 new_return(2);
14400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14401 new_return(3);
14402
14403 9 size_t count = quest_music.size();
14404
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (count > MAX_QUEST_MUSIC) // shouldn't happen
14405 {
14406 count = MAX_QUEST_MUSIC;
14407 box_out(" ...too many? truncating...");
14408 }
14409
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14410 {
14411 18 fake_pack_writing = (writecycle==0);
14412
14413 //section size
14414
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14415 new_return(4);
14416
14417 18 writesize = 0;
14418
14419
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(count,f))
14420 new_return(5);
14421
14422
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 18 times.
196 for (size_t q = 0; q < count; ++q)
14423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 if (auto ret = quest_music[q].write(f))
14424 return ret;
14425
14426
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle == 0)
14427 9 section_size = writesize;
14428 18 }
14429 9 new_return(0);
14430 9 }
14431
14432 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14433 {
14434
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14435 9 reset_combo_animations();
14436 9 reset_combo_animations2();
14437 9 strcpy(header.id_str,QH_NEWIDSTR);
14438 9 header.zelda_version = ZELDA_VERSION;
14439 9 header.internal = INTERNAL_VERSION;
14440 9 header.data_flags[ZQ_TILES] = true;
14441 9 header.data_flags[ZQ_CHEATS2] = 1;
14442 9 header.build=VERSION_BUILD;
14443
14444 char zinfofilename[2048];
14445 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14446
14447 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14448 9 box_out("Saving Quest...");
14449 9 box_eol();
14450 9 box_eol();
14451
14452
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14453
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14454
14455
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14456 return 1;
14457
14458
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14459
14460
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeheader(f,&header)!=0)
14461 return 2;
14462
14463
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14464
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14465
14466
14467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14468 {
14469 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14470
14471 box_out("Writing ZInfo...");
14472 if(inf)
14473 {
14474 if(writezinfo(inf,ZI)!=0)
14475 return 2;
14476
14477 pack_fclose(inf);
14478 box_out("okay.");
14479 }
14480 else box_out(" ...file failure");
14481 box_eol();
14482 }
14483 else
14484 {
14485
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14486
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writezinfo(f,ZI)!=0)
14487 return 2;
14488
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14489
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14490 }
14491
14492
14493
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14494
14495
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writerules(f,&header)!=0)
14496 return 3;
14497
14498
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14499
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14500
14501
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14502
14503
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14504 return 4;
14505
14506
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14507
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14508
14509
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14510
14511
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14512 return 5;
14513
14514
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14515
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14516
14517
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14518
14519
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14520 return 6;
14521
14522
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14523
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14524
14525
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14526
14527
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14528 return 7;
14529
14530
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14531
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14532
14533
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14534
14535
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisccolors(f,&header)!=0)
14536 return 8;
14537
14538
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14539
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14540
14541
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14542
14543
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14544 return 9;
14545
14546
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14547
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14548
14549
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14550
14551
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitems(f,&header)!=0)
14552 return 10;
14553
14554
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14555
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14556
14557
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14558
14559
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeweapons(f,&header)!=0)
14560 return 11;
14561
14562
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14563
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14564
14565
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14566
14567
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14568 return 12;
14569
14570
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14571
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14572
14573
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14574
14575
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14576 return 13;
14577
14578
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14579
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14580
14581
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14582
14583
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14584 return 14;
14585
14586
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14587
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14588
14589
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14590
14591
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14592 return 15;
14593
14594
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14595
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14596
14597
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14598
14599
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14600 return 16;
14601
14602
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14603
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14604
14605
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14606
14607
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemidis(f)!=0)
14608 return 17;
14609
14610
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14611
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14612
14613
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14614
14615
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14616 return 18;
14617
14618
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14619
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14620
14621
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14622
14623
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeinitdata(f,&header)!=0)
14624 return 19;
14625
14626
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14627
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14628
14629
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14630
14631
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeguys(f,&header)!=0)
14632 return 20;
14633
14634
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14635
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14636
14637
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14638
14639
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14640 return 21;
14641
14642
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14643
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14644
14645
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14646
14647
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14648 return 22;
14649
14650
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14651
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14652
14653
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14654
14655
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14656 return 23;
14657
14658
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14659
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14660
14661
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14662
14663
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14664 return 24;
14665
14666
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14667
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14668
14669
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14670
14671
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14672 return 25;
14673
14674
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14675
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14676
14677
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14678
14679
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14680 return 26;
14681
14682
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14683
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14684
14685
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Advanced Music...");
14686
14687
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(write_adv_music(f, &header)!=0)
14688 return 27;
14689
14690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14691
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14692
14693
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14694
14695
14696
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14697 {
14698 char const* kfname = filename;
14699 char keyfilename[2048]={0};
14700 zprint2("Writing key files for '%s'\n", kfname);
14701
14702 char temp_pw[QSTPWD_LEN] = {0};
14703 uint ind = 0;
14704 for(char const* ext : {"key","zpwd","zcheat"})
14705 {
14706 replace_extension(keyfilename, kfname, ext, 2047);
14707 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14708 char msg[80] = {0};
14709 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14710 msg[78]=13;
14711 msg[79]=10;
14712 pfwrite(msg, 80, fp);
14713 p_iputw(header.zelda_version,fp);
14714 p_putc(header.build,fp);
14715 char const* pwd = header.password;
14716 if(ind == 2) //.zcheat, hashed pwd
14717 {
14718 char hashmap = 'Z';
14719 hashmap += 'Q';
14720 hashmap += 'U';
14721 hashmap += 'E';
14722 hashmap += 'S';
14723 hashmap += 'T';
14724 for ( int q = 0; q < QSTPWD_LEN; ++q )
14725 {
14726 temp_pw[q] = header.password[q];
14727 temp_pw[q] += hashmap;
14728 }
14729 pwd = temp_pw;
14730 }
14731 pfwrite(pwd, strlen(pwd), fp);
14732 pack_fclose(fp);
14733 ++ind;
14734 }
14735 }
14736
14737 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14738 9 std::error_code ec;
14739
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 fs::rename(tmp_filename, filename, ec);
14740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14741 {
14742 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14743 return ec.value();
14744 }
14745
14746
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14747
14748 #ifdef __EMSCRIPTEN__
14749 em_sync_fs();
14750 #endif
14751
14752 9 return 0;
14753 9 }
14754
14755 // #ifdef _WIN32
14756 // static std::time_t to_time_t(FILETIME const& ft) {
14757 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14758 // t -= 116444736000000000ull;
14759 // t /= 10000000u;
14760 // return static_cast<std::time_t>(t);
14761 // }
14762 // #else
14763 // #endif
14764 template<typename TP>
14765 5 static std::time_t to_time_t(TP tp) {
14766 using namespace std::chrono;
14767 5 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14768 5 return system_clock::to_time_t(sctp);
14769 }
14770
14771 5 std::string get_time_last_modified_string(std::string path)
14772 {
14773
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 auto write_time = fs::last_write_time(path);
14774 // TODO: C++20 but not supported yet.
14775 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14776 5 std::time_t tt = to_time_t(write_time);
14777 5 std::tm *gmt = std::gmtime(&tt);
14778 5 std::stringstream buffer;
14779
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 buffer << std::put_time(gmt, "%Y-%m-%d");
14780
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string formattedFileTime = buffer.str();
14781 5 return formattedFileTime;
14782
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 }
14783
14784 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14785 {
14786 // Always backup quest if it was last saved in a different version of the editor,
14787 // or if this a new file and is overwritting another qst file.
14788
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 5 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14789 {
14790 5 std::string backup_name;
14791
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string last_mod = get_time_last_modified_string(filename);
14792
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (strlen(header.zelda_version_string) > 0)
14793 {
14794
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14795 5 }
14796 else
14797 {
14798 backup_name = fmt::format("{}", last_mod);
14799 }
14800
7/14
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
5 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14801
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 fs::path backup_path = fs::path("backups") / backup_fname;
14802
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (!fs::exists(backup_path))
14803 {
14804
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 fs::create_directories(fs::path("backups"));
14805
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (fs::copy_file(filename, backup_path))
14806 {
14807
5/10
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
5 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14808 5 }
14809 else
14810 {
14811 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14812 }
14813 5 }
14814 5 }
14815
14816 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14817 9 fake_pack_writing = false;
14818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14819 {
14820 box_out("-- Error saving quest file! --");
14821 box_end(true);
14822 }
14823 9 else box_end(false);
14824 9 return ret;
14825 }
14826
14827 9 int32_t save_quest(const char *filename, bool timed_save)
14828 {
14829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14830
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14831 char ext1[5];
14832 9 ext1[0]=0;
14833
14834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14835 {
14836 sprintf(ext1, "qt");
14837 }
14838 else
14839 {
14840 9 sprintf(ext1, "qb");
14841 }
14842
14843
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14844 {
14845 char backupname[2048];
14846 char backupname2[2048];
14847 char ext[12];
14848
14849 for(int32_t i=retention-1; i>0; --i)
14850 {
14851 sprintf(ext, "%s%d", ext1, i-1);
14852 replace_extension(backupname, filepath, ext, 2047);
14853
14854 if(exists(backupname))
14855 {
14856 sprintf(ext, "%s%d", ext1, i);
14857 replace_extension(backupname2, filepath, ext, 2047);
14858
14859 if(exists(backupname2))
14860 {
14861 remove(backupname2);
14862 }
14863
14864 rename(backupname, backupname2);
14865 }
14866 }
14867
14868 //don't do this if we're not saving to the same name -DD
14869 if(!timed_save && !strcmp(filepath, filename))
14870 {
14871 sprintf(ext, "%s%d", ext1, 0);
14872 replace_extension(backupname, filepath, ext, 2047);
14873 rename(filepath, backupname);
14874 }
14875 }
14876
14877 int32_t ret;
14878 9 ret = save_unencoded_quest(filename, compress, filename);
14879
14880 9 return ret;
14881 }
14882
14883 1 void center_zq_class_dialogs()
14884 {
14885 1 jwin_center_dialog(pwd_dlg);
14886 1 }
14887
14888 void zmap::prv_secrets(bool high16only)
14889 {
14890 mapscr *s = &prvscr;
14891 mapscr *t = prvlayers;
14892 int32_t ft=0;
14893
14894 for(int32_t i=0; i<176; i++)
14895 {
14896 if(!high16only)
14897 {
14898 for(int32_t j=-1; j<6; j++)
14899 {
14900 int32_t newflag = -1;
14901
14902 for(int32_t iter=0; iter<2; ++iter)
14903 {
14904 if(!t[j].valid)
14905 continue;
14906
14907 int32_t checkflag=combobuf[t[j].data[i]].flag;
14908
14909 if(iter==1)
14910 {
14911 checkflag=t[j].sflag[i];
14912 }
14913
14914 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
14915 if (ft != -1)
14916 {
14917 if(j==-1)
14918 {
14919 s->data[i] = s->secretcombo[ft];
14920 s->cset[i] = s->secretcset[ft];
14921 newflag = s->secretflag[ft];
14922 }
14923 else
14924 {
14925 t[j].data[i] = t[j].secretcombo[ft];
14926 t[j].cset[i] = t[j].secretcset[ft];
14927 newflag = t[j].secretflag[ft];
14928 }
14929 }
14930 }
14931
14932 if(newflag >-1)
14933 {
14934 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14935 }
14936 }
14937 }
14938
14939 //if(true)
14940 //{
14941 int32_t newflag = -1;
14942
14943 for(int32_t iter=0; iter<2; ++iter)
14944 {
14945 int32_t checkflag=combobuf[s->data[i]].flag;
14946
14947 if(iter==1)
14948 {
14949 checkflag=s->sflag[i];
14950 }
14951
14952 if((checkflag > 15)&&(checkflag < 32))
14953 {
14954 s->data[i] = s->secretcombo[(checkflag)-16+4];
14955 s->cset[i] = s->secretcset[(checkflag)-16+4];
14956 newflag = s->secretflag[(checkflag)-16+4];
14957 // putit = true;
14958 }
14959 }
14960
14961 if(newflag >-1) s->sflag[i] = newflag;
14962
14963 for(int32_t j=0; j<6; j++)
14964 {
14965 if(!t[j].valid) continue;
14966
14967 int32_t newflag2 = -1;
14968
14969 for(int32_t iter=0; iter<2; ++iter)
14970 {
14971 int32_t checkflag=combobuf[t[j].data[i]].flag;
14972
14973 if(iter==1)
14974 {
14975 checkflag=t[j].sflag[i];
14976 }
14977
14978 if((checkflag > 15)&&(checkflag < 32))
14979 {
14980 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14981 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14982 newflag2 = t[j].secretflag[(checkflag)-16+4];
14983 }
14984 }
14985
14986 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14987 }
14988 }
14989
14990 //FFCs
14991 word num_ffcs = s->numFFC();
14992 for(word i=0; i<num_ffcs; ++i)
14993 {
14994 if(!high16only)
14995 {
14996 for(int32_t iter=0; iter<1; ++iter)
14997 {
14998 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14999
15000 if(iter==1)
15001 {
15002 checkflag=s->sflag[i];
15003 }
15004
15005 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15006 if (ft != -1)
15007 {
15008 s->ffcs[i].data = s->secretcombo[ft];
15009 s->ffcs[i].cset = s->secretcset[ft];
15010 }
15011 }
15012 }
15013
15014 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15015 {
15016 for(int32_t iter=0; iter<1; ++iter)
15017 {
15018 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15019
15020 if(iter==1)
15021 {
15022 // FFCs can't have flags! Yet...
15023 }
15024
15025 if((checkflag > 15)&&(checkflag < 32))
15026 {
15027 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15028 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15029 }
15030 }
15031 }
15032 }
15033 }
15034